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.
Answers:
Maybe a possible answer here:
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.
Get the author of the message
You need to look the id of the author.
API:
- discord.on_message(message): Get a message, a Message,
- class discord.Message: look for author attribute, a Member,
- class discord.Member: look id attribute.
if message.content.startswith('$register'):
await message.channel.send('You are registered successfully')
print(message.author.id)
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.
Maybe a possible answer here:
EDIT:
enabling
intents.typing
and turning on the intents within the
Discord developer portal can access theon_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.
Get the author of the message
You need to look the id of the author.
API:
- discord.on_message(message): Get a message, a Message,
- class discord.Message: look for author attribute, a Member,
- class discord.Member: look id attribute.
if message.content.startswith('$register'):
await message.channel.send('You are registered successfully')
print(message.author.id)