.addArgument 不是 Discord 机器人的函数

.addArgument is not a function Discord bot

这是我的 Discord 命令模块代码,出于某种原因,这表明 .addArgument 不是一个函数。

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.`);
    }

);

它只是给了我这个:

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

您收到此错误的原因是 SlashCommandBuilder 中没有名为 .addArgument() 的内容。如果要添加数字或频道等参数,则需要使用 .addNumberOption().addChannelOption()。添加频道和号码选项需要使用的方式如下:

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

您可以在此处了解有关斜杠命令和选项的更多信息 => Options | discord.js