2
votes

I have a Discord bot that runs discord.py and when I use the help function, there is sometimes a small delay of a few seconds between messages. When a living user is typing on Discord, it usually shows 3 small dots alternating shades while saying Example is typing. How can I make this show up with my bot? I have a function that doesn't work right now, which is and


async def balabala (ctx):
    async with ctx.typing():
        await message.channel.send(prefix + "random [Value 1] [Value 2]  -  Gives a random number between Value 1 and Value 2, inclusive")
    await ctx.send(prefix + "choose [Value 1] (Value 2) (Value 3) etc.  -  Chooses a random value from the list of values you provide") # what you want to do after typing    
@client.event
async def on_message(message):
    if message.content.lower() == prefix + "help":
        await message.channel.send("The prefix for this bot is " + prefix)
        await message.channel.send("Note: Do not actually enter [](required) or ()(Not required)")
        await message.channel.send(prefix + "help  -  Shows this message" )
        await message.channel.send("Hello  -  Gives a hello back, because you are so nice")
        await message.channel.send(prefix + "invite - Gives an invite to the bot, and Canary versions")
        
        await balabala()

The error that shows up is

  File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "discordbotcanary.py", line 45, in on_message
    await balabala()
  File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 354, in __call__
    return await self.callback(*args, **kwargs)
TypeError: balabala() missing 1 required positional argument: 'ctx'

1

1 Answers

2
votes

You'll be able to open a context manager of a Messageable object (e.g. TextChannel, DMChannel) and perform your tasks inside of it.

I'm using asyncio.sleep() as an example delay:

@bot.command()
async def hello(ctx):
    async with ctx.typing():
        await asyncio.sleep(2) # some tasks go here, the sleep is just for a delay
    await ctx.send(f"Hello, {ctx.author.mention}!") # what you want to do after typing

References: