Error with deploying commands

I followed the discord.js guide and made my own command, but when I try and run node deploy-commands.js, it has an error with the dban.js file that i have made for my new command.
11 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!
1techy.
1techy.OP16mo ago
[email protected] node.js v18.12.1 code:
const { SlashCommandBuilder } = require('discord.js');
const { client } = require('./config');
module.exports = {
data: new SlashCommandBuilder()
.setName('dban')
.setDescription('Bans a user from all servers the bot is in.')
.addParam('user', {
description: 'The user to ban.',
type: 'user',
})
.addParam('reason', {
description: 'The reason for the ban',
type: 'string',
})
.addParam('duration', {
description: 'The duration of the ban, in minutes',
type: 'integer',
})
await execute(interaction) {
const user = interaction.options.user;
const reason = interaction.options.reason;
const duration = interaction.options.duration;

const allowedUsers = require('./config.json').allowedUsers;

if (!allowedUsers.includes(interaction.user.id)) {
await interaction.reply('You are not authorized to use this command.');
return;
}

const guilds = client.guilds.cache;

for (const guild of guilds) {
guild.ban(user, { reason });
}
await interaction.reply(`Successfully banned ${user} from all of the servers. Reason: **${reason}**. Duration: **${duration} minutes.**`);
}
const { SlashCommandBuilder } = require('discord.js');
const { client } = require('./config');
module.exports = {
data: new SlashCommandBuilder()
.setName('dban')
.setDescription('Bans a user from all servers the bot is in.')
.addParam('user', {
description: 'The user to ban.',
type: 'user',
})
.addParam('reason', {
description: 'The reason for the ban',
type: 'string',
})
.addParam('duration', {
description: 'The duration of the ban, in minutes',
type: 'integer',
})
await execute(interaction) {
const user = interaction.options.user;
const reason = interaction.options.reason;
const duration = interaction.options.duration;

const allowedUsers = require('./config.json').allowedUsers;

if (!allowedUsers.includes(interaction.user.id)) {
await interaction.reply('You are not authorized to use this command.');
return;
}

const guilds = client.guilds.cache;

for (const guild of guilds) {
guild.ban(user, { reason });
}
await interaction.reply(`Successfully banned ${user} from all of the servers. Reason: **${reason}**. Duration: **${duration} minutes.**`);
}
Error:
/home/runner/utcutil30/commands/whitelistedCmds/dban.js:19
await execute(interaction) {
^^^^^

SyntaxError: Unexpected reserved word
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1088:15)
at Module._compile (node:internal/modules/cjs/loader:1123:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/home/runner/utcutil30/deploy-commands.js:15:19)
at Module._compile (node:internal/modules/cjs/loader:1159:14)

Node.js v18.12.1
/home/runner/utcutil30/commands/whitelistedCmds/dban.js:19
await execute(interaction) {
^^^^^

SyntaxError: Unexpected reserved word
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1088:15)
at Module._compile (node:internal/modules/cjs/loader:1123:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/home/runner/utcutil30/deploy-commands.js:15:19)
at Module._compile (node:internal/modules/cjs/loader:1159:14)

Node.js v18.12.1
treble/luna
treble/luna16mo ago
you forgot a , and also .addParam isnt a thing
1techy.
1techy.OP16mo ago
how would i add a paramiter then? where?
treble/luna
treble/luna16mo ago
between your builder and execute addStringOption etc if you followed the guide, the guide should explain it
1techy.
1techy.OP16mo ago
so i can also deleete the type: 'string', part too?
treble/luna
treble/luna16mo ago
you can delete the whole addParam function also your handling logic is incorrect i recommend following the guide and your ban thing is also api spam
1techy.
1techy.OP16mo ago
the bot is only in 4 servers and its a private bot
treble/luna
treble/luna16mo ago
oh also thats invalid js
1techy.
1techy.OP16mo ago
yeah im new to this whole js thing
treble/luna
treble/luna16mo ago
your await needs to be async then i recommend checking out #resources as a strong js understanding is required
Want results from more Discord servers?
Add your server