我正在尝试制作一个机器人程序,当消息具有反应时进行响应
这是有错误的线路:
confirmation = await Bot.wait_for("reaction_add", check=check)
这是完整的代码:
import discord
from discord.utils import get
from discord.ext import commands
from discord.ext.commands import Bot
client = commands.Bot(command_prefix = "!")
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.command(pass_context = "true")
async def ping(ctx):
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ["✅"] and reaction.message == message
message = await ctx.send("Test emoji")
await message.add_reaction("✅")
confirmation = await Bot.wait_for("reaction_add", check=check)
channel = Bot.get_channel(704609444092182632)
if confirmation:
await channel.send("yay")
client.run(TOKEN)
当我跑的时候!ping命令我得到错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: wait_for() missing 1 required positional argument: 'event'
这是类Bot
的一个方法,这意味着您应该在commands.Bot
的实例上运行它。
在第6行,您创建了一个实例&将其称为client
,因此不要使用Bot.wait_for
(类),而是使用client.wait_for
。
@client.command(pass_context = "true")
async def ping(ctx):
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ["✅"] and reaction.message == message
message = await ctx.send("Test emoji")
await message.add_reaction("✅")
confirmation = await client.wait_for("reaction_add", check=check)
if confirmation:
await ctx.send("yay")
你不需要添加通道检查,只需输入await ctx.send("yay")
错误代码指的是你的await Bot.wait_for
,你的Bot使用的是client
,所以你不能调用Bot