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.
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.
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.
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.
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.
If you use the rewrite branch, then all Messageable
s 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!")
@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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With