如何使用Discord机器人发送消息?

时间:2019-05-16 16:43:18

标签: python discord discord.py

我需要我的机器人将消息发送到任何频道,但是当我使用bot.say()或bot.send_message并调用命令时,它给出了一个错误。我看了一个视频教程,做了完全一样的事情,多次检查。如果这些方法不起作用,那么还有什么其他方式可以发送消息?

我已经查看了有关Bot类的整个Discord python API,但是与消息发送没有任何关系。

import random
from discord.ext.commands import Bot

BOT_PREFIX = "!"
TOKEN = "the bot's very long token"

client = Bot(command_prefix=BOT_PREFIX)


@client.command(name="8ball",
                description="Answers a yes/no question",
                brief="Answers from beyond",
                aliases=["eightball", "eight-ball", "eight_ball"],
                pass_context=True)
async def eight_ball(context):
    possbile_responses = [
        "Maybe",
        "Possibly",
        "Absolutely",
        "No way",
        "Yes",
        "No",
        "Too hard to tell"
    ]
    await client.say(random.choice(possbile_responses) + ", " + context.message.author.mention)

client.run(TOKEN)

Ignoring exception in command 8ball:
Traceback (most recent call last):
  File "C:\Users\barni\PycharmProjects\Jarvis\venv\lib\site-packages\discord\ext\commands\core.py", line 63, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:/Users/barni/PycharmProjects/Jarvis/my_bot2.py", line 25, in eight_ball
    await client.say(random.choice(possbile_responses) + ", " + context.message.author.mention)
AttributeError: 'Bot' object has no attribute 'say'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\barni\PycharmProjects\Jarvis\venv\lib\site-packages\discord\ext\commands\bot.py", line 860, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\barni\PycharmProjects\Jarvis\venv\lib\site-packages\discord\ext\commands\core.py", line 698, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\barni\PycharmProjects\Jarvis\venv\lib\site-packages\discord\ext\commands\core.py", line 72, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Bot' object has no attribute 'say'

0 个答案:

没有答案