Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 机器人如何对自己的消息作出反应?_Python_Discord_Discord.py - Fatal编程技术网

Python 机器人如何对自己的消息作出反应?

Python 机器人如何对自己的消息作出反应?,python,discord,discord.py,Python,Discord,Discord.py,我现在正在开发我自己的机器人,它应该能完成更多的功能。但一开始,它应该对自己的信息做出反应。但是,这似乎不起作用,因为错误会一次又一次地发生 我一直收到以下错误: 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 in

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

我一直收到以下错误:

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, 'As RufusVS mentioned in the comments: 
send_message
is not part of the class
commands.Bot
. Instead we send the embed with
await ctx.send()
and then react to it by defining the message that you sent.

Have a look at the following code:

@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
忽略命令create中的异常:
回溯(最近一次呼叫最后一次):
文件“D:\Python\lib\site packages\discord\ext\commands\core.py”,第85行,包装为
ret=等待coro(*args,**kwargs)
文件“D:\PythonCode\DiscordBot\method2.py”,第15行,在create中
msg=wait bot.send_message(message.channel,embed=createEmbed)
AttributeError:“Bot”对象没有“发送消息”属性
我不知道问题出在哪里,也找不到解决办法

我的代码如下所示:

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, 'As RufusVS mentioned in the comments: 
send_message
is not part of the class
commands.Bot
. Instead we send the embed with
await ctx.send()
and then react to it by defining the message that you sent.

Have a look at the following code:

@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
导入不一致
从discord.ext导入命令
bot=commands.bot(命令前缀='pp!')
@机器人事件
_ready()上的异步定义:
打印('bot现在处于活动状态并登录到{0.user}'。格式(bot))
@bot.command()
异步定义创建(ctx):
createEmbed=discord.Embed(title='何时需要我提醒您?',description=':regional_indicator_a:每10分钟\n:regional_indicator_b:每30分钟\n:regional_indicator_c:每小时')
emojis=['\n{区域指标a}','\n{区域指标b}','\n{区域指标c}']
msg=wait bot.send_message(message.channel,embed=createEmbed)

wait bot.add_reaction(msg,AsRufusVS在注释中提到:
send_message
不是类
命令的一部分。bot
。相反,我们使用
wait ctx.send()
发送嵌入,然后通过定义您发送的消息对其作出反应

查看以下代码:

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, 'As RufusVS mentioned in the comments: 
send_message
is not part of the class
commands.Bot
. Instead we send the embed with
await ctx.send()
and then react to it by defining the message that you sent.

Have a look at the following code:

@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
@bot.command()
异步定义创建(ctx):
createEmbed=discord.Embed(title='YourTitle',description='YourDescription')#Embed
msg=wait ctx.send(embed=createEmbed)#定义bot发送的消息
等待消息。添加你的反应(“你的反应”)#添加你的反应

请再次查看。

您需要阅读错误消息。您正在尝试调用在类
命令中不可用的方法
send\u message
。Bot
您需要查看文档。请记住,自库创建以来,discord.py API已重写两次。您需要记住,如果你正在阅读一本使用不再存在的函数的旧教程,我觉得自己太愚蠢了。谢谢鲁弗斯、西尔维奥·马约洛和多米尼克。现在终于可以使用了。:)