【问题标题】:Ignoring exception in on_message in pycharm using discord.py使用 discord.py 忽略 pycharm 中 on_message 中的异常
【发布时间】:2020-11-03 21:11:44
【问题描述】:

当我在我的不和谐服务器中键入“!hello”时,我的机器人应该说“你好(作者)” 但是当我运行命令时会出现这个错误

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Leo\PycharmProjects\untitled\venv\lib\site-packages\discord\client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "C:/Users/Leo/PycharmProjects/untitled/Discord-bot.py", line 16, in on_message
    await message.channel.send('Hello {0.author.mention}'.format(message))
AttributeError: 'Channel' object has no attribute 'send'

我不知道该做什么,这个网站上的其他事情和我做的事情不同。这是我的脚本:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged in as')
        print(self.user.name)
        print(self.user.id)
        print('------')

    async def on_message(self, message):
        # we do not want the bot to reply to itself
        if message.author.id == self.user.id:
            return

        if message.content.startswith('/Hi'):
            await message.channel.send('Hello {0.author.mention}'.format(message))

client = MyClient()
client.run('TOKENWENTHERE')

【问题讨论】:

  • 嗨,我复制粘贴了您的代码并尝试了它,它对我有用。您确定您的 discord 库版本是最新的吗?
  • 是的,这似乎应该有效。你已经使用pip3 install discord.py 安装了模块,对吧?

标签: python pycharm discord.py


【解决方案1】:

原来我使用的是 discord.py 0.64 版!感谢@Vate 和@MLarionv!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多