我正在执行一个PURGE命令,但我不知道如何将其使用限制为具有MANAGE_MESSAGES权限的用户.
我提供了客户端的源代码.on("Ready")部分以及整个命令.
对这件事真的一无所知,谢谢你的帮助.
client.on('ready', async () => {
try {
const command = await client.application.commands.create({
name: 'purge',
PermissionFlagsBits: 'MANAGE_MESSAGES',
description: 'Deletes messages',
options: [
{
name: 'amount',
description: 'The amount of messages to delete',
type: 4,
required: true,
},
],
defaultPermission: false,
});
console.log(`Registered ${command.name} command`);
} catch (error) {
console.error(error);
}
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'purge') {
const amount = interaction.options.getInteger('amount');
if (amount > 100) {
return interaction.reply({ content: 'You can only delete 100 messages at a time!', ephemeral: true });
}
if (amount < 1) {
return interaction.reply({ content: 'You must delete at least 1 message!', ephemeral: true });
}
await interaction.channel.bulkDelete(amount, true).catch(error => {
console.error(error);
interaction.reply({ content: 'There was an error trying to delete messages in this channel!', ephemeral: true });
});
interaction.reply({ content: `Successfully deleted ${amount} messages!`, ephemeral: true });
}
});