I am trying to make a discord bot in which I want that as soon as user type into command channel his/her discord id must be printed

Question:

 if message.content.startswith('$register'):
        await message.channel.send('You are registered successfully')
        userk = print(client.user.id)

I am using Discord.py and Iam trying to get the Discord user id of a user when they type into a channel. But I am not able to find the specific command for that current api of discord is not saying anything about that.the above code is only printing my bot’s id.

Asked By: Mudit Dagar

||

Answers:

Maybe a possible answer here:

Discord-py When a user is typing, how to make the bot to follow the typing and when the user stop, the bot also stop typing in a specific channel?

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:

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}")

Here is an example:

@client.event
async def on_typing(channel, user, when):
    print(f"{user.id=}")

Check the discord.on_typing(channel, user, when) documentation.
user parameter can be a User or a Member, but either way, it have an id attribute.

Answered By: Dorian Turba

Get the author of the message

You need to look the id of the author.

API:

if message.content.startswith('$register'):
    await message.channel.send('You are registered successfully')
    print(message.author.id)
Answered By: Dorian Turba
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.