I would like to update from time to time What I was having trouble with discord (what I couldn't find when I searched the site) Please make a note of it for reference ~
python 3.8.1 windows10
Codes that I didn't ride unexpectedly
This time we will use the event (on_message) when the message is received, but it can be applied to other things as well. This code specifies the time To use this
import asyncio
Must be declared
discord.py
@client.event
async def on_message(message):
guild = message.guild
if message.content == '/role':
reaction_message = await message.channel.send('pls reaction good or bad')
reaction_message_id = reaction_message.id
ad_role_good = guild.get_role(YOUR_ROLE_ID)
ad_role_bad = guild.get_role(YOUR_ROLE_ID)
def check(reaction,user):
return user == message.author and reaction.message.id == reaction_message_id
try:
reaction, user = await client.wait_for('reaction_add', timeout=120.0, check=check)
except asyncio.TimeoutError:
await message.channel.send('Time is up! !! !!')
else:
if str(reaction.emoji) == "\U0001f44d":
await message.author.add_roles(ad_role_good)
await message.channel.send('good')
elif str(reaction.emoji) == '\U0001f44e':
await message.author.add_roles(ad_role_bad)
await message.channel.send('bad')
else:
await message.channel.send('Not supported')
Recommended Posts