I'm new to python and making discord bots so sorry if this is a noob question but I'm stuck.
Been trying to figure it out for hours.
I'm writing a simple bot that will loop through a list of 28 objects and randomly choose 4 of them. Then send those 4 choices into chat so people can vote for their choice.
Last night I was using
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!maps'):
await message.delete()
channel = client.get_channel(800086126173225010)
await channel.send('**New poll! Vote below now for tomorrow\'s map!**')
choice = random.sample(maps,4)
for x in range(0, 4):
mapemp.append(emoji[x]+" - "+choice[x])
msg = await channel.send('\n\n'.join(mapemp))
for x in range(0,4):
await msg.add_reaction(emoji[x])
mapemp.clear()
This works fine. But then I found out about @bot.command instead of @client.event so I'm trying to switch to that. However, when I try to run the command it returns
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'Command' object is not iterable
@bot.command(pass_context=True)
async def maps(ctx):
await ctx.message.delete()
channel = bot.get_channel(800086126173225010)
await channel.send('**New poll! Vote below now for tomorrow\'s map!**')
choice = random.sample(list(maps,4)
for x in range(0, 4):
mapemp.append(emoji[x]+" - "+choice[x])
msg = await channel.send('\n\n'.join(mapemp))
for x in range(0,4):
await msg.add_reaction(emoji[x])
mapemp.clear()
What makes @bot.command so different than @client.event that I can't iterate through the choices?
I didnt use to have random.sample(list(maps,4) but when I try to run it with just random.sample(maps,4) I get a different error.
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: Population must be a sequence or set. For dicts, use list(d).
So I changed it to random.sample(list(maps,4) if that matters.
random.sample(list(maps,4)torandom.sample(list(maps,4))?choice = random.sample(list(maps),4)discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'Command' object is not iterable`random.sample(list(maps,4))it returnsdiscord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: list() takes at most 1 argument (2 given)