python - 从用户名 Discord.py 获取用户 ID
问题描述
我想制作一个程序来获取您输入的用户名的用户 ID。这是我到目前为止所拥有的:
from discord.ext import commands
client = commands.Bot(description="a", command_prefix=".", self_bot = False)
client.remove_command('help')
@client.event
async def on_ready():
user = await client.fetch_user("pirace#4637")
print(user)
client.run('token')
它给了我这个错误:
400 Bad Request (error code: 50035): Invalid Form Body
In user_id: Value "pirace#4637" is not snowflake.
有谁知道我会怎么做?
解决方案
如果你想使用你必须使用的用户名discord.utils.get()
,在这种情况下结合client.get_guild(GUILD_ID)
.
from discord.ext import commands
client = commands.Bot(description="a", command_prefix=".", self_bot = False)
client.remove_command('help')
@client.event
async def on_ready():
guild = client.get_guild(GUILD_ID)
user = discord.utils.get(guild.members, name="pirace", discriminator="4637")
print(user)
client.run('token')
推荐阅读
- r - 用于数据分布的 ggplot 语法
- java - 找不到静态资源
- python - 更新用户后如何发送邮件?
- python-3.x - 内存随着 matplotlib 和 tkinter 的增加而增加
- javascript - 如何将 Skeleton.css 添加到我的 React 应用程序?
- javascript - 通过单击 HTML 中的链接覆盖 JS 变量
- c# - Visual Studio中的C#应用程序,一个类看不到另一个类中的文本框
- r - 将行添加到具有组内数据总和的数据框
- python - 将 paramiko 和 sshtunnel 与 docker alpine 一起使用的 libssl 问题
- javascript - 不使用 Redux 管理状态