机器人如何对其自己的消息做出反应?

时间:2021-05-24 01:49:59

标签: python discord discord.py

我现在正在开发自己的机器人,它最终应该会执行更多功能。但是一开始它应该对自己的消息做出反应。但是,这似乎不起作用,因为错误一次又一次地发生。

我不断收到以下错误:

Ignoring exception in command create:
Traceback (most recent call last):
  File "D:\Python\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "D:\PythonCode\DiscordBot\method2.py", line 15, in create
    msg = await bot.send_message(message.channel,embed=createEmbed)
AttributeError: 'Bot' object has no attribute 'send_message'"

我不知道问题出在哪里,也无法找到解决方案。

我的代码如下所示:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix = 'pp!')

@bot.event
async def on_ready():
    print('bot is now active and logged into {0.user}'.format(bot))

@bot.command()
async def create(ctx):
    createEmbed = discord.Embed(title='When would you like me to remind you?', description=':regional_indicator_a: Every 10 minutes\n:regional_indicator_b: Every 30 minutes\n:regional_indicator_c: Every hour')
    emojis = ['\n{regional indicator a}', '\n{regional indicator b}', '\n{regional indicator c}']
    msg = await bot.send_message(message.channel,embed=createEmbed)
    await bot.add_reaction(msg, '?')

1 个答案:

答案 0 :(得分:0)

正如评论中提到的 RufusVSsend_message 不是 commands.Bot 类的一部分。相反,我们发送带有 await ctx.send() 的嵌入,然后通过定义您发送的消息对其做出反应。

看看下面的代码:

@bot.command()
async def create(ctx):
    createEmbed = discord.Embed(title='YourTitle', description='YourDescription') # Embed
    msg = await ctx.send(embed=createEmbed) # Define the message that the bot sends
    await msg.add_reaction("YourReaction") # Add your reaction

也请再看看 docs