这个问题在这里已有答案:
有人能告诉我如何使用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,但它没有用。无论如何,我将使用该用户名将其写入文件,但这只是为了这个问题的例子。谢谢!
您需要使用.name
字段来获取用户对象的全局。 https://discordpy.readthedocs.io/en/latest/api.html#user
username = ctx.message.author.name
要获取其服务器特定的昵称,您需要使用.display_name
字段。
username = ctx.message.author.display_name