Notes on upgrading discord.py from async to rewrite version

No ... w

Even if you answer a question on the discord board, "Ah ... Wai was old ..." I'm sorry for those who answered that, and above all, it's a pity that I'm using a much older version.

I'm sure other than me "I know I have to upgrade, but I don't know what kind of wall is waiting ... I'll do it next month." I believe that there are people who think that, and I hope I can share my courage with them.

Basically,

  1. Make it the latest discord.py. ↓
  2. For the time being, try moving it as before ↓
  3. I get an error ↓
  4. Try searching for the method with the error at https://discordpy.readthedocs.io/ja/latest/migrating.html and fix it.

If you just repeat it, it will be quite good.

Also, it is safer to separate it from the existing environment with virtualenv of pyenv. Also, if you manage it with git etc., let's cut the branch (naturally)

Let's write it.

id changed from str type to int type.

If there is a place where the id is taken and something is processed or branched, and if there is a place surrounded by a single coat to distinguish it, I will remove it. If you really want to do it as usual,

str(client.user.id)

I'll put it in the form of.

Posting a message

async

await client.send_message(message.channel, "message")

rewrite

await message.channel.send(res)

Image attachment

async

await client.send_file(message.channel, res)

rewrite

await message.channel.send(file=discord.File(res,))

You use the same method as when sending a message. It is assumed that res contains the path to the image you want to attach. Also, be careful where you pass it as a tuple. (If you want to paste more than one, you can usually separate them with commas)

Grant reaction

async

await client.add_reaction(message, e)

rewrite

await message.add_reaction(e)

That ... more ...?

Um ...

It's over! !! w

I thought there were more, but when I tried it, it was like this. (In my case)

Perhaps the number of correction lines was about 5 lines. (There were two lines where the id was directly written and judged by str)

The most important thing in this article is that it's not a big deal except if you try it, so let's start doing it for the time being! !! I think that will be the case!

Maybe I just overlooked it and I have to fix something else, If there is such a thing, I would like to add it as appropriate.

Recommended Posts

Notes on upgrading discord.py from async to rewrite version
Notes on machine learning (updated from time to time)
Notes on using MeCab from Python
Notes on how to use pywinauto
Notes on how to use featuretools
Notes on accessing dashDB from python
Notes on how to use doctest
Notes on how to write requirements.txt
Update Python on Mac from 2 to 3
[Latest version] Play YouTube videos on discord.py!
Connecting from python to MySQL on CentOS 6.4
[Updated from time to time] PostmarketOS related notes
[2020 version] How to install Python3 on AWS EC2
Cross-compile windows version from nim on arch | linux
Notes on oct2py calling Octave scripts from Python