蟒蛇 Discord.py - 不和谐.消息作者输出一个奇怪的结果



我是 Discord API 的新手,正在尝试制作自己的机器人。我试图让它记录发送消息"-clan"的人的昵称(不是用户名(。例:

Surge - Today at 15:01
-clan

这应该输出结果"浪涌"。

但是,相反,它会输出以下内容:

surge epic bot!!!BOT - Today at 15:01
<member 'author' of 'Message' objects>

我不知道它为什么要这样做,所以一些意见将不胜感激。

我当前的代码:

@client.event
async def on_message(message):
    if message.content.startswith("-clan"):
        await client.send_message(message.channel, discord.Message.author)

谢谢!

只要discord.Message.author.name,name 是 discord.Author 类的属性。

await client.send_message(message.channel, discord.Message.author) 将作者对象的__repr__发送到消息所在的通道。

你想要的是await client.send_message(message.channel, 'Surge!') 因为第二个参数是您要发送的消息,第一个参数是目的地。

此外,看起来您正在将命令放在一个大的on_message事件切换案例中,如果我没记错的话,您是;我不建议这样做。而是使用 commands 扩展,discord.py 的异步分支不能很好地记录这一点并且大部分都无法使用,首先我建议您使用 discord.py 的重写分支并在此处阅读有关命令扩展的文档。

要发送消息作者,只需使用 message.author .

最新更新