【问题标题】:discord.py wait_for is not reading messagesdiscord.py wait_for 没有读取消息
【发布时间】:2021-02-21 22:51:24
【问题描述】:

我正在制作自己的不和谐机器人。一旦用户发送-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')

没有错误。我删除了尝试,除了查看是否有任何错误,但唯一显示的错误是超时。

【问题讨论】:

    标签: discord discord.py


    【解决方案1】:

    那是因为你没有在 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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-27
      • 1970-01-01
      • 2019-07-10
      • 1970-01-01
      • 2020-10-17
      • 2021-07-10
      • 1970-01-01
      相关资源
      最近更新 更多