【发布时间】:2020-06-19 00:59:34
【问题描述】:
我正在尝试为我和我的朋友制作一个有趣的机器人。我想要一个命令来说明作者的用户名是什么,带或不带标签。我尝试查找如何执行此操作,但没有一个适用于我的代码当前设置的方式。
import discord
client = discord.Client()
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$WhoAmI'):
##gets author.
await message.channel.send('You are', username)
client.run('token')
我希望这是有道理的,我看到的所有代码都使用ctx 或@client.command
【问题讨论】:
-
你试过
discord.Message.author.name吗? -
另一个问题是它只是与程序的常规流程内联,你的
if应该在on_message@client.event中,见here -
@SeanBreckenridge 我编辑并修复了它。我的脚本是正确的,我只是在发布我的问题时忘记包含它,感谢您告诉我!
-
@Daniil 这不是消息的实例,这只是消息对象。
-
@Daniil 我出错了,
Class 'Message' has no 'author' member
标签: python python-3.x discord.py discord.py-rewrite