Search code examples
pythondiscorddiscord.pybotsdelay

Discord.py add delay to bot response


I am using an on_message function in discord.py and after recieving the message the bot responds: await message.channel.send("response") but this happens instantly, is there any way for me to delay this reponse for a couple of seconds?


Solution

  • You can use await asyncio.sleep(seconds_to_sleep) which adds async-friendly delay to your bot actions

    import asyncio
    
    # ... then in a cog
        @commands.Cog.listener()
        async def on_message(self, message: discord.Message):
            if message.author == self.bot.user:
                return
            await asyncio.sleep(5)
            await message.channel.send("response")