【问题标题】:Python Discord.py - discord.Message.author outputting a strange resultPython Discord.py - discord.Message.author 输出一个奇怪的结果
【发布时间】:2018-06-13 06:51:54
【问题描述】:

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

Surge - Today at 15:01
-clan

这应该输出结果“Surge”。

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

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)

谢谢!

【问题讨论】:

    标签: python python-3.x discord discord.py


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      另外,如果我没记错的话,您似乎将命令放在一个大的 on_message 事件开关盒中;我不推荐这个。而是使用commands 扩展名,discord.py 的异步分支没有很好地记录这一点,而且大部分都没有使用,首先我建议您使用rewrite branch of discord.py 并阅读有关commands extension here 的文档。

      【讨论】:

        【解决方案3】:

        只要做discord.Message.author.name,name就是discord.Author类的一个属性。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-12-19
          • 1970-01-01
          • 2013-12-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-12-30
          • 2017-12-05
          相关资源
          最近更新 更多