[PYTHON] Code memo that I was having trouble with not being on the discord.py site

discord.py memo

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 ~

Preface

python 3.8.1 windows10

Code list

Codes that I didn't ride unexpectedly

(1) Code that assigns a position to each reaction pictogram

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

Code memo that I was having trouble with not being on the discord.py site
A memo that I touched the Datastore with python
I was addicted to not being able to use Markdown on pypi's long_description
Log when I was worried that I could not connect to Wi-Fi on Linux
I was in trouble because the behavior of docker container did not change
I played with Floydhub for the time being
I tried playing with the calculator on tkinter
CUM_plot, which I often see at the manufacturing site, did not fall on the net, so I made it with python
Note that I was addicted to npm script not passing in the verification environment
[Pyhton] I want to solve the problem that tkinter does not work on MacOS11
When I crawl the webapi that appears during rendering, it was played with CORS
Here is one of the apps with "artificial intelligence" that I was interested in.
Solved the problem that the image was not displayed in ROMol when loaded with PandasTools.LoadSDF.
The story when I was using IntelliJ on Linux and could not input Japanese
I investigated the problem that I could not get more than 101 images with google images download
I was in trouble because I couldn't push with heroku
I felt that I ported the Python code to C ++ 98.
The story that Japanese output was confused with Django
Work memo that I tried i18n with Flask app
Memo (March 2020) that I was addicted to when installing Arch Linux on MacBook Air 11'Early 2015