自动更改 Discord“关于我”

TKi*_*ima 6 python http python-requests discord discord.py

问题

您可能知道,在 Discord 中,有一个“关于我”部分。

本节是对您可以自己编写的配置文件的描述。

机器人可以有一个“关于我”部分。

我想要做的是在discord.py中自动编辑这个“关于我”部分;例如,机器人的“关于我”部分每小时都会发生变化。

我尝试过的

我搜索了很长时间的一些答案,但没有找到任何相关的内容。

我看到您可以使用开发者门户修改“关于我”,但它不是自动化的。

我看到有人说“这在discord.py V2中可以”但没有找到

也许可以通过 HTTP 请求解决这个问题,但这只是一个假设,我不太擅长这个主题。

代码

@bot.event
async def on_ready():
    while 1:
         await change_the_about_me_section(str(random.randint(0,1000))
         time.sleep(3600)
         # change_the_about_me_section isn't a real function
         # I just wanted to show an exemple of what I wanted to do
Run Code Online (Sandbox Code Playgroud)

TKi*_*ima 7

有一个答案。

您可以使用 Python 只需几行代码即可将其完全自动化。

与请求库。

您只需首先包含以下请求:

import requests
Run Code Online (Sandbox Code Playgroud)

然后,提出补丁请求

requests.patch(url="https://discord.com/api/v9/users/@me", headers= {"authorization": token}, json = {"bio": abio} )
# With token your token, and abio a string like "hello"

Run Code Online (Sandbox Code Playgroud)

而且...就是这样:)

(注意:您也可以使用帐户的颜色而accent_color不是bio以及横幅的颜色来做到这banner一点bio