Banning a previous user by ID

Command
module.exports = {
name: `test`,
description: `dummy command`,
defaultMemberPermissions: ['Administrator'],
cooldown: 0,
type: ApplicationCommandType.ChatInput,
options: [{
name: `user_id`,
description: `The user you want to ban`,
type: ApplicationCommandOptionType.User,
required: true
}],
/**
* @param {CommandInteraction} interaction
*/
async execute(interaction, client) {
const { options, member, guild, channel, user } = interaction;

await interaction.deferReply({ ephemeral: true }).catch(err => console.error(`${path.basename(__filename)} There was a problem deferring an interaction: `, err));

// Resolve the user by ID
const targetToBan = options.get('user_id');

// Ban the resolved user
guild.bans.create(targetToBan)

interaction.deleteReply();
}
}
module.exports = {
name: `test`,
description: `dummy command`,
defaultMemberPermissions: ['Administrator'],
cooldown: 0,
type: ApplicationCommandType.ChatInput,
options: [{
name: `user_id`,
description: `The user you want to ban`,
type: ApplicationCommandOptionType.User,
required: true
}],
/**
* @param {CommandInteraction} interaction
*/
async execute(interaction, client) {
const { options, member, guild, channel, user } = interaction;

await interaction.deferReply({ ephemeral: true }).catch(err => console.error(`${path.basename(__filename)} There was a problem deferring an interaction: `, err));

// Resolve the user by ID
const targetToBan = options.get('user_id');

// Ban the resolved user
guild.bans.create(targetToBan)

interaction.deleteReply();
}
}
targetToBan seems to resolve a user object
{
name: 'user_id',
type: 6,
value: 'xxxxxxxxxxxxxxxx',
user: User {
id: 'xxxxxxxxxxxxxx',
bot: false,
system: false,
flags: UserFlagsBitField { bitfield: 0 },
username: 'xxxxxxxxxxxx',
discriminator: '3947',
avatar: '8b404e300e2c3e1a3c65cd488cac3098',
banner: undefined,
accentColor: undefined
}
}
{
name: 'user_id',
type: 6,
value: 'xxxxxxxxxxxxxxxx',
user: User {
id: 'xxxxxxxxxxxxxx',
bot: false,
system: false,
flags: UserFlagsBitField { bitfield: 0 },
username: 'xxxxxxxxxxxx',
discriminator: '3947',
avatar: '8b404e300e2c3e1a3c65cd488cac3098',
banner: undefined,
accentColor: undefined
}
}
Error
Error [BanResolveId]: Couldn't resolve the user id to ban.
at GuildBanManager.create (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\discord.js\src\managers\GuildBanManager.js:157:20)
at Object.execute (C:\Users\proba\OneDrive\Desktop\4DC\commands\slash_commands\administration\test.js:34:20)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'BanResolveId'
}
Error [BanResolveId]: Couldn't resolve the user id to ban.
at GuildBanManager.create (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\discord.js\src\managers\GuildBanManager.js:157:20)
at Object.execute (C:\Users\proba\OneDrive\Desktop\4DC\commands\slash_commands\administration\test.js:34:20)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'BanResolveId'
}
2 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
probablyraging
probablyragingOP2y ago
Ah you're right, thank you for pointing that out
Want results from more Discord servers?
Add your server