Discord.py specific user ID

0

Hello stack overflow community!

Just wanted to ask why when If I give a specific user ID to a ban command it return me the following(The purpose of this command its just when someone with bans perms enters it w/o ping or introducing any input and only the command it gets banned, aka a mini troll ban command):

enter image description here

Here's the command code:

>     @client.command() @commands.has_permissions(ban_members = True)
> #async def niceroger(ctx,Member:discord.User=None): async def niceroger(ctx,Member:discord.User=None):
>     user=669680584376713259
>     username = client.get_user(user)
>     #user2=discord.get_member(669680584376713259)
>     reason = "Bye bye"
>     await ctx.guild.ban(username, reason=reason)
>     #await ctx.guild.ban(user, reason=reason)
>     #await ctx.guild.ban(Member, reason = reason)
>     await ctx.channel.send(f"Bye <@669680584376713259>")

Best regards, Engineer

discord discord.py python
2021-11-23 16:56:28
1

1

Firstly, make sure to always enter the error message as just a code block instead of an image. It seems that your issue is just an AttributeError and that username has no id. I think the issue here is this line:

username = client.get_user(user)

According the documentation, client.get_user(id) will return None if it can't find a user with the given id. So make sure that your user variable is correct.

2021-11-23 19:51:41

Thank you for respone, this is the error pastebin: pastebin.com/eVHR58dG Sadly, for some reason it still showing the same error? How do I set up the variable correctcly?
Engineer

I think the variable is setup correctly however the id itself may be wrong. The error is occurring because client.get_user(user) is returning None and assigning to username. And later the code is trying to get username.id, however it doesn't exist because username is None. So make sure that the number assigned to user is correct so client.get_user(user) doesn't return None
Roopesh-J

Sorry to disturb again, just retrying to remember everything from my python basic course, now i added de > client.get_user(user) and now its a different story. Would you mind to do an example code or refer to one so I can see how it works: pastebin.com/FLeVRi2V
Engineer

No worries. Are you sure that 669680584376713259 is the correct id. Because if so, I don't see why your issue persists. I took your code from that pastebin linked and updated it here. Not a 100% sure if it works but give it a shot. If it doesn't then I think the id is wrong.
Roopesh-J

Thank you, that made me progress a lot and we just passed a bit, now i found the issue and is that the line "member = ctx.message.guild.get_member(user_id)" never manages to find ANY discord ID, neither mine, neither the provided one from an ALT acc. Is this bc we are not setting the field "user_id = 669680584376713259" correctly?
Engineer

Hm that's odd. Okay try this user = client.fetch_user(id). This will return a User instead of a Member so you ban them like this await ctx.guild.ban(user, reason=reason). The user_id is set correctly, as long as it is an int it is set correctly. The value itself could be incorrect but it seems you already clarified that.
Roopesh-J

Hmm, i changed the bot response before the "ban" gets applied to see if it responds with the user by mentioning it but it outputs something that i never seen? Pastebin: pastebin.com/fj5VuZcf
Engineer

Oh I apologize, my mistake. It should be await client.fetch_user(id), it is a coroutine so it must be awaited.
Roopesh-J

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................