Ban command.

How do I make my ban command work with Banning their Discord ID and when you mention them within the slash command. https://pastebin.com/iqeQZJbP
Pastebin
const Discord = require('discord.js');module.exports = async (clien...
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.
19 Replies
d.js toolkit
d.js toolkit16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
grass
grass16mo ago
you dont need to fetch the member, you can just use interaction.options.getMember() and what isnt working as expected?
X_DigitalNinja
X_DigitalNinjaOP16mo ago
When I ban them I get this error DiscordAPIError[10007]: Unknown Member at handleErrors (/app/node_modules/@discordjs/rest/dist/index.js:687:13) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async SequentialHandler.runRequest (/app/node_modules/@discordjs/rest/dist/index.js:1072:23) at async SequentialHandler.queueRequest (/app/node_modules/@discordjs/rest/dist/index.js:913:14) at async _REST.request (/app/node_modules/@discordjs/rest/dist/index.js:1218:22) at async GuildMemberManager._fetchSingle (/app/node_modules/discord.js/src/managers/GuildMemberManager.js:221:18) at async module.exports (/app/src/commands/moderation/ban.js:11:18)
grass
grass16mo ago
no, you get that error when you fetch them as i said, you can use getMember(), which will be either a GuildMember or null
ShompiFlen
ShompiFlen16mo ago
the only thing you need to ban a member, or specifically add a ban to a guild, is the user id. you can achieve this through guild.bans.create() passing the user id https://old.discordjs.dev/#/docs/discord.js/main/class/GuildBanManager?scrollTo=create it will not matter if they are or not present in the guild
X_DigitalNinja
X_DigitalNinjaOP16mo ago
So like this? const member = await interaction.guild.members.fetch(guild.bans.create('user').id);
ShompiFlen
ShompiFlen16mo ago
Nop. Why would you need the member object after you ban them?
X_DigitalNinja
X_DigitalNinjaOP16mo ago
Sorry but I am starting to not get it but what part of that code do I need to replace, I just don't get it I been trying to look it up and have been trying to find how to fix it but I can not find the solution. I know this is dumb to ask and It could be as simple as 1. 2. 3. But Idk
ShompiFlen
ShompiFlen16mo ago
const member = await interaction.guild.members.fetch(interaction.options.getUser('user').id); this fetch you are doing here is failing because you are passing the Id of a user that is not on the guild at the moment grass told you that you can directly use interaction.options.getMember() instead of fetching it but since in this case the member is not in the guild this is not going to work either my suggestion was that since you already seem to have a user.id that you can use, you can instead directly add the ban to the guild through guild.bans.create(user.id)
X_DigitalNinja
X_DigitalNinjaOP16mo ago
How how do I defined the Guild
ShompiFlen
ShompiFlen16mo ago
you can get it from the interaction as long as the interaction is made within a guild
d.js docs
d.js docs16mo ago
property Integration#guild The guild this integration belongs to
ShompiFlen
ShompiFlen16mo ago
whoops thats an integration
ShompiFlen
ShompiFlen16mo ago
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.
X_DigitalNinja
X_DigitalNinjaOP16mo ago
So add it to the slash command?
ShompiFlen
ShompiFlen16mo ago
add it in your code... the thing is, you are doing some things wrong here. You can't fetch a member if the member is not in the guild thats why you are getting the first error, but your code only works if the member still is on the guild. So you have to decide, you either only use this command with members that are still in the guild, or you generalize it to work both ways
X_DigitalNinja
X_DigitalNinjaOP16mo ago
Yea I like it to work both ways.
ShompiFlen
ShompiFlen16mo ago
we already gave you options, its up to you to implement it so for example. If the user is not present in the guild, you can do something like this const member = await guild.members.fetch(user.id).catch( () => null ). if the promise rejects for whatever reason then member will be null, you can check that and branch to either use the member object to ban them or ban through guild.bans
X_DigitalNinja
X_DigitalNinjaOP16mo ago
Sorry for the late reply, I been busy with work and what not, But it seems I am getting this error guild is not defined
Want results from more Discord servers?
Add your server