Discord返回用户名[重复]

问题描述 投票:1回答:1

这个问题在这里已有答案:

有人能告诉我如何使用Python(Discord.py)将用户名返回到某个变量中?

假设我有这个命令:

@bot.command(pass_context=True)
async def somecmd(ctx):
username = #HOW TO RETURN IT HERE?    
await bot.say(username)

我尝试使用message.author.id,但它没有用。无论如何,我将使用该用户名将其写入文件,但这只是为了这个问题的例子。谢谢!

python bots discord username discord.py
1个回答
1
投票

您需要使用.name字段来获取用户对象的全局。 https://discordpy.readthedocs.io/en/latest/api.html#user

 username = ctx.message.author.name

要获取其服务器特定的昵称,您需要使用.display_name字段。

username = ctx.message.author.display_name
© www.soinside.com 2019 - 2024. All rights reserved.