#Ban Command Not Working

26 messages · Page 1 of 1 (latest)

spare perch
#

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).

meager patrolBOT
#

• 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.

crimson granite
#

string.ban is not a function
use guild.bans.create(id)

low moss
#

you can use ids in user options, no need to have a string for the name and one for the id

crimson granite
#

^ also

spare perch
#

I tried guild.bans.create(id) and got an error: ReferenceError: guild is not defined

white maple
#

Define it

spare perch
#

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.

white maple
#

But then you may as well use interaction.client.channels

maiden yoke
#

yeah interaction.guilds doesnt exist

interaction.guild.channels.cache.get("CHANNEL ID").send(...)``` is better
spare perch
#

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.

white maple
#

Docs*

#

Yes it’s that i think

spare perch
#

So interaction.guild.bans.create(userid){reason: banreason}?

white maple
spare perch
#

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.'

thick forum
#

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"

meager patrolBOT
thick forum
spare perch
#
const interactionUser = await interaction.guild.members.fetch(userid)
        let userName = interactionUser.username```

Still returning 'undefined.'
#

Never mind, I got it working.

Just had to replace interactionUser.username with interactionUser.user.username.