Discord.py on_typing

Viewed 1740

I've got some issues using discord.py. I'd like to use on_typing event for logging or something, but it doesn't work. I've tried to do this

intents = discord.Intents.default()
intents.typing = True
client = discord.Client(intents=intents)

Here is all code. on_ready and on_message works fine but on_typing. How to make it work?

@client.event
async def on_ready():
    logger.info("But successfully runned!")

@client.event
async def on_typing(channel, user, when):
    logger.info("{} is typing message in {} : {}".format(user.name, channel, when))

@client.event
async def on_message(message):
    logger.info("{} has just sent {}".format(message.author, message.content))
2 Answers

I believe this is your mistake:

intents = discord.Intents.default()
intents.typing = True
client = discord.Client(intents=intents)

do not write the line intents.typing = True, just enable all intents at the beginning. To do that, you would delete the intents.typing = True line, and then replace the intents = discord.Intents.default() with intents = discord.Intents.all(), and then that's it (Make sure you've enabled intents in the Discord Dev Portal)! Depending on your bots ping, it won't detect typing immediately, but a few milliseconds after. So, the ending code would look something like this:

intents = discord.Intents.all()
client = discord.Client(intents=intents)

And then you calling the on_typing event is correct! Hope this helped! If you have any follow up questions about my code or unforeseen errors feel free to follow up!

Have you tried replacing the on_typing event and the on_message event with @client.listen such as:

@client.event
async def on_ready():
    logger.info("But successfully runned!")

@client.listen
async def on_typing(channel, user, when):
    logger.info("{} is typing message in {} : {}".format(user.name, channel, when))

@client.listen
async def on_message(message):
    logger.info("{} has just sent {}".format(message.author, message.content))

I came across this issue when I was making a join message this seemed to fix it.

Related