0
votes

Context

I am making a discord.py(rewrite-v1.0+) bot, I created a cog with some basic sql and python to make a chatbot, but when a 'message' event occurs the wait_for method completely ignores it.
I am new to Discord.py so any help would be greatly appreciated!



Mini code:

"""ai cog"""
import discord
from discord.ext import commands
import asyncio

class ai(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command(aliases=['c','ch','cha'])
    async def chat(self, ctx, *, message:str):
        Bot = 'Hello!'

        # I am guessing problem is here
        def nobotspeakshere(message):
                if message.author.bot == True:
                    return False

        while True:
            
            # try:
            msg = await user.wait_for('message', check=nobotspeakshere)
            #                                    ^^^^^^^^^^
            #                  The problem seems to be here.             
            # except asyncio.TimeoutError:
                # await ctx.send('Bot: bye')
                # break
            
            you = msg.content
            
            print(you)

            if you.lower() in ["", "bye!", "bye"]:
                return await ctx.send('Bot: ' + Bot)

            await ctx.send('Bot: Bye!')

            #some working sql
            #sql gives bot = "something else"

def setup(bot):
    bot.add_cog(ai(bot))


Expected output

Prints variable 'you' and continues execution

Output

Ignores the message entered in a channel

Expected Problem

nobotspeakshere function is not functioning as expected.



1

1 Answers

1
votes

Your function never returns True, only False (if the author is a bot) or None (the default return value). As None is a falsy value, treats it as false.

The best change would be to always return the opposite of message.author.bot

msg = await user.wait_for('message', check=lambda message: not message.author.bot)