When a user is typing, how to make the bot to also start the typing event in a certain channel and stop when the user who was typing stopped.
ctx.trigger_typing/ctx.typing cannot be used since we need to track the user if he/she is typing.
So how to do that?
EDIT:
enabling intents.typing
and turning on the intents within the Discord developer portal can access the on_typing
event, you can just enable all intents from your code like:
intents = discord.Intents.all()
client = discord.Client(intents=intents)
The typing event can be called simply using an on_typing
event,
@client.event
async def on_typing(channel, user, when):
print(f"{user} is typing message in {channel} {when}")
If you want to get your bot to have a typing status, you can use ctx.typing():
followed with what It would send.
Here's an on_message
event example,
@client.event
async def on_message(message):
async with message.channel.typing():
await message.channel.send('Typing status invoked')
await client.process_commands(message)
Command usage, you can also add a sleep event to control the typing time
@client.command()
async def type(ctx):
async with ctx.typing():
await asyncio.sleep(2)
await ctx.send("Typing...")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.