Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
.addArgument is not a function Discord bot

Here is my Discord command module code, for some reason this is spitting out that .addArgument is not a function.

const Discord = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');

data = new SlashCommandBuilder()
    .setName('purge')
    .setDescription('Purges a number of messages from the channel.')
    .addArgument('number', 'The number of messages to purge.')
    .addArgument('channel', 'The channel to purge messages from.')
    .setExecute(async (interaction, args) => {
        const channel = interaction.guild.channels.cache.find(c => c.name === args.channel);
        if (!channel) return interaction.reply('Channel not found.');
        const messages = await channel.messages.fetch({ limit: args.number });
        await channel.bulkDelete(messages);
        interaction.reply(`Purged ${messages.size} messages.`);
    }

);

It just gives me this:

TypeError: (intermediate value).setName(...).setDescription(...).addArgument is not a function

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The reason you are getting this error is because there is nothing called .addArgument() in the SlashCommandBuilder. If you want to add arguments like numbers or channels, you need to use .addNumberOption() or .addChannelOption(). The way you will need to use to add a channel and number option is like this:

.addNumberOption(option => {
    return option
        .setName('number') // Set the name of the argument here
        .setDescription('The number of messages to purge.') // Set the description of the argument here
        .setRequired() // This is optional. If you want the option to be filled, you can just pass in true inside the .setRequired() otherwise you can just remove it
})
.addChannelOption(option => {
    return option
        .setName('channel') 
        .setDescription('The channel to purge messages from.')
        .setRequired()
})

You can learn more about slash commands and options here => Options | discord.js

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!