discord - discord.py wait_for 没有读取消息
问题描述
我正在制作自己的不和谐机器人。一旦用户发送-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')
没有错误。我删除了尝试,除了查看是否有任何错误,但唯一显示的错误是超时。
解决方案
那是因为您没有在 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')
推荐阅读
- ruby-on-rails - Rubocop Rails/UniqueValidationWithoutIndex 过火
- google-sheets - Google 表格 IMPORTXML 无法获取网址
- python-3.x - 无法使用 seaborn.kdeplot() 绘制 numpy 数据集
- c# - Infragistics ultraoptionset - 如何添加 &(项目快捷方式)
- computer-vision - 如何将带有 grad 的 Torch 张量列表转换为张量
- survey - Microsoft Forms 调查真的是匿名的吗?
- java - 以下 JPQL 查询中有什么错误或不正确的地方?
- javascript - 查找数组中的字符串是否包含在同一数组中的另一个字符串中
- python - Altair 热图标记文本
- optimization - 基于训练数据计算两个参数输出的深度学习算法