So I'm writing this custom embed command for my discord.py bot. The bot asks a few questions then send a custom embed with the variables that the user specifies. The bot asks the first question and after i input the first variable/text, it stops responding.
Full code:
@commands.command(aliases=['custom', 'cembed'])
async def customembed(self,ctx):
questions = ["What should be the name of the embed?", "What should be the desc","What is the colour of the embed?"]
answers = []
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
for i in questions:
await ctx.send(i)
msg=""
try:
msg = await client.wait_for('message', timeout=15.0, check=check)
except asyncio.TimeoutError:
await ctx.send("You didn't answer in time, please be quicker next time!")
return
else:
answers.append(msg.content)
title = answers[1]
desc = answers[2]
colour = answers[3]
embed = discord.Embed(title = f"{title}", description = f"{desc}", color = colour)
await ctx.channel.send(embed = embed)
I assume that the try block is at fault here:
for i in questions:
await ctx.send(i)
msg=""
try:
msg = await client.wait_for('message', timeout=15.0, check=check)
except asyncio.TimeoutError:
await ctx.send("You didn't answer in time, please be quicker next time!")
return
else:
answers.append(msg.content)
Any help would be appreciated! Thanks
P.S I just created my SO account day so I'm pretty new to all of this, sorry if I say or do something wrong
Update: I fixed some of the code that you guys suggested i'd change, but it still wouldn't say anything after sending the first question. Weird.
@commands.command(aliases=['custom', 'cembed'])
async def customembed(self,ctx):
questions = ["What should be the name of the embed?", "What should be the desc", "What is the colour of the embed?"]
answers = []
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
for i in questions:
await ctx.send(i)
msg=""
try:
msg = await self.client.wait_for('message', timeout=15.0, check=check)
except asyncio.TimeoutError:
await ctx.send("You didn't answer in time, please be quicker next time!")
return
else:
answers.append(msg.content)
title = answers[0]
desc = answers[1]
colour = answers[2]
embed = discord.Embed(title = f"{title}", description = f"{desc}", color = int(colour))
await ctx.channel.send(embed = embed)
Update 2:
I got it to register the first question/answer AND the second question/answer, but it doesnt register the color variable. I had to change await self.client.wait_for('message', timeout=15.0, check=check) to await self.bot.wait_for('message', timeout=15.0, check=check)
Update 3:
I fixed it! I had to change int(colour) to int(color, 16)`. Now it works and uses all the variables that i want it to use, thanks to whoever helped me.
Here's the working code:
@commands.command(aliases=['custom', 'cembed'])
async def customembed(self,ctx):
questions = ["What should be the name of the embed?", "What should be the desc", "What is the colour of the embed?"]
answers = []
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
for i in questions:
await ctx.send(i)
msg=""
try:
msg = await self.bot.wait_for('message', timeout=15.0, check=check)
except asyncio.TimeoutError:
await ctx.send("You didn't answer in time, please be quicker next time!")
return
else:
answers.append(msg.content)
title = answers[0]
desc = answers[1]
colour = answers[2]
embed = discord.Embed(title = f"{title}", description = f"{desc}", color = int(colour, 16))
await ctx.channel.send(embed = embed)