Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
4

Discord.py How to ping users?

WackyPythonWithaLemon1912
WackyPythonWithaLemon1912

How do I let my discord bot ping users? I'm using it for a welcome style message. I still need to figure out how to add channel ID but the pinging problem has stopped me before

@client
.event
async def on_member_join(member):
await member.send(f"{member.name} has joined")

This is what I used

2 years ago

Voters

Comments

TopNew
1
aynonyme971
aynonyme971

Why commands.Bot is invalid ?

4 months ago
1
Teslestien
Teslestien

@client.event async def on_message(message): if message.content.startswith("$summon"): await message.channel.send(f"{message.author.mention} has been summoned.")

1 year ago
4
CircuitSacul
CircuitSacul

Discord uses special formatting for pings: <@user_id>. With discord.py, there are two easy ways to ping a user:

# If you have the ctx object (inside a command) await ctx.send(ctx.message.author.mention) # If you have a message object (such as the on_message event) await message.channel.send(message.author.mention) # If you know their ID await ctx.send("<@" + str(user_id) + ">")
2 years ago
3
WackyPythonWithaLemon1912
WackyPythonWithaLemon1912

Thank you! Now I just need to figure out how to use it in the on_member_join event

@LD1

2 years ago
2
Coder100
Coder100
@client.event async def on_member_join(member): await member.send(f"@{member.name} has joined")

if that doesn't work, maybe try

@client.event async def on_member_join(member): await member.send(f"<@!{member.id}> has joined")
2 years ago
1
CircuitSacul
CircuitSacul

@Coder100
It's always <object>.mention, .name and .id will send just their name or their id.

2 years ago
1
Coder100
Coder100

yeah so i encapsulated with the ping <@! and >

@LD1

2 years ago
1
CircuitSacul
CircuitSacul

@Coder100
Oh sorry I missed that.

2 years ago
1
WackyPythonWithaLemon1912
WackyPythonWithaLemon1912

So i tried those commands and also kind of combined it with LD1's response, and now i think it's the channel id that's the problem.

@client.event async def on_member_join(welcomeChannel, member): welcomeChannel = client.get_channel(490042165926428672) await welcomeChannel.send("<@" + str({member.name}) + ">")

Do you know how to make it message the specific channel?
Coder100

2 years ago
1
CircuitSacul
CircuitSacul

@slavstic
See if this fixes it

@client.event async def on_member_join(welcomeChannel, member): welcomeChannel = client.get_channel(490042165926428672) await welcomeChannel.send("<@" + str(member.id) + ">")
2 years ago
1
WackyPythonWithaLemon1912
WackyPythonWithaLemon1912

@LD1
Nope. No error or anything. Pretty odd

2 years ago
1
CircuitSacul
CircuitSacul

Try this then

@client.event async def on_member_join(welcomeChannel, member): try: print("Event Called") welcomeChannel = client.get_channel(490042165926428672) print("Welcome Channel": welcomeChannel) await welcomeChannel.send(member.mention) print("Sent") except Exception as e: print(type(e), e)

@slavstic

2 years ago
Load more