我正在制作自己的不和谐机器人。一旦用户发送 -find
我希望机器人等待用户响应它,机器人就会发送一条消息。机器人在等待,但无法识别消息。
@commands.command()
async def find(self, ctx):
members = [self.xxx, self.xxx, self.xxx]
member = random.choice(members)
image = member[0]
await ctx.send(f'{image}')
def check(m):
m.author == ctx.author and m.channel == ctx.channel
try:
await self.client.wait_for('message', timeout=8.0, check=check)
await ctx.send('yay!')
except:
await ctx.send('booo you suck')
try: @commands.command()
async def find(self, ctx):
members = [self.xxx, self.xxx, self.xxx]
member = random.choice(members)
image = member[0]
await ctx.send(f'{image}')
def check(m):
m.author == ctx.author and m.channel == ctx.channel
await self.client.wait_for('message', timeout=8.0, check=check)
await ctx.send('yay!')
except:
await ctx.send('booo you suck')
没有错误。我删除了尝试,除了查看是否有任何错误,但显示的唯一错误是超时。
答案 0 :(得分:0)
那是因为你没有在 check 函数中返回任何东西,所以它永远不会评估为 True 因为默认情况下函数返回 None 可以用作 False
@commands.command()
async def find(self, ctx):
members = [self.xxx, self.xxx, self.xxx]
member = random.choice(members)
image = member[0]
await ctx.send(f'{image}')
def check(m):
return m.author.id == ctx.author.id and m.channel.id == ctx.channel.id
try:
await self.client.wait_for('message', timeout=8.0, check=check)
await ctx.send('yay!')
except:
await ctx.send('booo you suck')