Home > Back-end >  mention a member with discord.py
mention a member with discord.py

Time:10-05

Hello I wanna mention a specific member in my guild I know my code is a mess can you show me my mistakes please?

async def ping(ctx):
    guild=ctx.guild(889583100286369832)
    sido=guild.get_member('439800066312503297')
    await ctx.send(sido.mention)

CodePudding user response:

You haven't posted the error message yet. but discord requires a special intent to get guild data about users.

enter image description here

You don't need the guild data on a user to @ them however, so you shouldn't need to enable that. you can do this:

myid = '<@[ID GOES HERE]>'
await client.send_message(message.channel, ' : %s is the best ' % myid)

CodePudding user response:

Another way:

sido = await bot.fetch_user(439800066312503297)
await ctx.send(sido.mention)

You need intents for this: https://discordpy.readthedocs.io/en/stable/intents.html

CodePudding user response:

Without seeing the error, I'm unsure if this is the problem but guild likely doesn't have a get_member() method and you should instead use bot.get_member()

In the event that this isn't the cause of your problem, the best way to workaround this issue for your specific use case would be to mention the user with <@ID>

await ctx.send("<@{}>".format("439800066312503297"))
# Or
await ctx.send("<@439800066312503297>")

Formatting here is unnecessary if you want to hard-code the ID, but I recommend using it if you want to dynamically change the ID in the future.

  • Related