Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Discord bots display the "Bot is typing ..." status?

So if I have a long command like this:

@bot.command(pass_context=True)
async def longCommand(ctx):
   #typing status
   sleep(10)
   bot.say("Done!")

Didn't find anything in the documentation or here, unfortunately.

like image 214
David Fischer Avatar asked Jul 09 '18 19:07

David Fischer


People also ask

How do you make Discord bot look like it's typing?

Conclusion. Adding typing indicators to your bot is pretty simple. Just use the with keyword and ctx. typing to create a context handler for your typing task.

How can you tell if someone is typing on Discord?

On the far right of the area you can click on that channel, the indicator would show up telling you someone is typing there. The indicator can also appear on top of the corner of guilds or folders.

How do I set Discord bot status to invisible?

To do it, you will have to type in “bot. user. setStatus('Invisible')”. You can later replace the word “invisible” with online, dnd, or idle.


3 Answers

EDIT: Newer versions of discord require you to use the new syntax:

@bot.command()
async def mycommand(ctx):
    async with ctx.typing():
        # do expensive stuff here
        await asyncio.sleep(10)
    await ctx.send('done!')

Older versios used this:

@bot.command(pass_context=True)
async def longCommand(ctx):
   await bot.send_typing(ctx.channel)
   await asyncio.sleep(10)
   await bot.say("Done!")

Remember to use await on every asynchronous call to coroutines.

like image 188
nosklo Avatar answered Oct 19 '22 17:10

nosklo


If you use the rewrite branch, then all Messageables have a typing context manager that allows you to type indefinitely, and a trigger_typing coroutine that displays the typing message for a few seconds.

@bot.command()
async def longCommand(ctx):
   async with ctx.typing():
        await sleep(10)
   await ctx.send("Done!")
like image 7
Patrick Haugh Avatar answered Oct 19 '22 16:10

Patrick Haugh


@bot.command()
async def type(ctx):
    await ctx.channel.trigger_typing()
    await asyncio.sleep(5)
    await ctx.send("Done!")

This worked for me! Im using Discord.py (not rewrite)

like image 1
Mathis Kirchner Avatar answered Oct 19 '22 16:10

Mathis Kirchner