我想做一个程序,将获得您输入的用户名的用户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.
有人知道我会怎么做吗?
发布于 2021-04-26 21:15:33
如果您想使用用户名,则必须使用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')
发布于 2021-04-25 06:45:16
fetch_user
接受雪花,或者更简单地说,id。使用usernername获取用户是可能的,方法如下:
@bot.command()
async def info(ctx, user:discord.User):
return await ctx.send(user.name)
只有当用户和你的机器人共享一个行会,并且区分大小写时,这才能起作用。因此,要么将有效的用户id作为整数放在bot.fetch_user
中,要么使用我提供的代码
https://stackoverflow.com/questions/67248017
复制相似问题