Reputation: 33
Hi I wanted to code a discord.py vocab learn bot. My code looks like this
@client.event
async def on_message(message):
vocab_list = ["suburb",
"timer"]
if message.content.startswith('-vokabeln'):
channel = message.channel
random_vokabel = random.choice(vocab_list)
await channel.send(random_vokabel)
if random_vokabel == "suburb":
async def check(m):
return m.author == message.author and m.channel == message.channel
msg = await client.wait_for('message', check=check)
if msg.content == 'Vorort':
await message.channel.send("richtig!")
await msg.add_reaction("➡️")
else:
await message.channel.send("Leider falsch die Lösung wäre **Vorort** gewesen")
await msg.add_reaction("➡️")
async def check(reaction, user):
return user == message.author and str(reaction.emoji) == '➡️'
reaction, user = await client.wait_for('reaction_add', check=check)
await message.channel.send(random_vokabel)
if random_vokabel == "timer":
async def check(m):
return m.author == message.author and m.channel == message.channel
msg = await client.wait_for('message', check=check)
if msg.content == 'Timer':
await message.channel.send("richtig!")
await msg.add_reaction("➡️")
else:
await message.channel.send("Leider falsch die Lösung wäre **Timer** gewesen")
await msg.add_reaction("➡️")
async def check(reaction, user):
return user == message.author and str(reaction.emoji) == '➡️'
reaction, user = await client.wait_for('reaction_add', check=check)
await message.channel.send(random_vokabel)
await client.process_commands(message)
But when I run this code the bot reacts on its own reaction So the bot reacts on the user message and then the wait for reaction thing gets activated by the bot reaction So the bot activates itself
How can I make it that the bot dont gets activated by his own reaction
Another problem is that when the wait for reaction gets activated the bot sends a new vocab but after this my code wont work. So the bot dont react to anything because the whole function gets not activated. The bot sends a random message but the -vokabeln gets not activated Is there a way to let work -vokabeln and the reaction thing?
And the last and biggest problem is that I will add like 100 more vocabs This will make the code so big and unefficient Is there another way to make two lists with vocabs and translations so the bot choose a vocab and then he gets the right translation for it and he will wait for the right translation I just want to make the code more efficient and not so long
Upvotes: 1
Views: 66
Reputation: 36
async def check(reaction, user):
return not user.bot and user == message.author and str(reaction.emoji) == '➡️'
Check to see if the reactor is a bot or not.
Upvotes: 1