为了好玩,我正试图用Python编写一个Discord机器人,根据我为Discord.js找到的文档(https://discord.js.org/#/docs/main/stable/class/User)应该有一个user.tag
和user.username
给你一个字符串(我正在为用户的子类message.author
寻找一种方法(。这在discord.py
中不起作用,我在discord.py
中找不到类似的东西。有人知道怎么做吗?
参考代码:
@client.event
async def on_message(message):
print(message.content + " sent by " + message.author.username + message.author.tag)
if message.author == client.user:
return
Reply = "Test"
await message.channel.send(Reply)
如果您正在寻找鉴别器(9999
(,请使用Member.discriminator
message.author.discriminator
或者,如果您正在查找全名(HelloWorld#9999
(
message.author.name
您的源代码
@client.event
async def on_message(message):
print(message.content + " sent by " + message.author.name)
if message.author == client.user:
return
Reply = "Test"
await message.channel.send(Reply)
参考:
Member.discriminator
Member.name
没有Member.tag
这回事我想你在找Member.discriminator
tag = message.author.discriminator
或者,如果您正在查找全名(example#1234
(
name = str(message.author) # Or `message.author.name`
参考:
Member.discriminator
Member.name
您可以这样做:
name = message.author.name
然后拼接字符串得到标签,通过#
拼接