Ban Command Not Working
I'm trying to create a ban command for my bot that primarily works via the user's ID number, but I keep getting an error when I try testing it.
The code I am using is here: https://pastebin.com/p5BPttKn
The error I get is:
TypeError: userid.ban is not a function
Is it even possible to do this, or have I missed something (blatantly obvious, given my track record).Pastebin
Ban Command - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
16 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.string.ban is not a function
use guild.bans.create(id)
^ also
And how would I attach the reason to that?
I tried
guild.bans.create(id)
and got an error: ReferenceError: guild is not defined
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Tweaked a couple of things; the ban is now being applied, but the message explaining why the user was banned isn't being sent to the channel I want.
TypeError: Cannot read properties of undefined (reading 'cache')
Code has been updated on Pastebin.Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Okay, that's working now. All that remains is to attach a reason to the ban (because I hate seeing 'no reason provided' in my ban list.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
So
interaction.guild.bans.create(userid){reason: banreason}
?Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
All right, final question (I hope).
How do I get the username from the ID number?
I tried
interaction.guild.members.cache.get(userid)
but that returns 'undefined.'The member won't always be in the cache try fetching it instead
if you just need the username I'd be easiest to just fetch the "user" not the "member"
nvm this one i picked the wrong one you want this one instead
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Still returning 'undefined.'
Never mind, I got it working.
Just had to replace
interactionUser.username
with interactionUser.user.username
.
Everything appears to be working as I'd hoped.
Thanks for the assistance. 👍