Search code examples
discorddiscord.py

Discord name = discord ID, how to find it?


I have a problem. I can only unban members only by their discord ID (@username doesn't work!) I can't unban people with @username. Is there a command like @username = Discord profile id or sth? How can I fix it? This is my code:

    @commands.command()
    @commands.guild_only()
    @commands.has_guild_permissions(ban_members=True)
    async def unban(self, ctx, member, *, reason="xyz"):
        member = await self.bot.fetch_user(int(member))
        await ctx.guild.unban(member, reason=reason)
        await ctx.channel.send(f"***{member.mention}xyz***")

Solution

  • Hey so if you want to get id of someone with ping I got you. A ping is equal to:

    <@user_id>
    

    This is a command to get id from ping:

    @client.command()
    async def get_id(ctx, user_to_get_id):
        user_to_get_id = user_to_get_id.replace("<",""
        user_to_get_id = user_to_get_id.replace("@","")
        user_to_get_id = user_to_get_id.replace(">","")
        await ctx.reply(str(user_to_get_id))
    

    So you can use this code to add to the unban command.