【发布时间】:2021-09-05 03:08:25
【问题描述】:
我想删除我之前使用命令添加到数组中的参数,我制作的代码:
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
const multipleArgs = args.slice(1).join(" ");
const banWordAdded = new Discord.MessageEmbed()
.setColor('#42f59b')
.setTitle("Ban word added:")
.setFooter(multipleArgs)
const banWordRemoved = new Discord.MessageEmbed()
.setColor('#42f59b')
.setTitle("Ban word removed:")
.setFooter(multipleArgs)
if (banWords.some(word => message.content.toLowerCase().includes(word))) {
message.delete()
message.channel.send("Don't say that!");
} else if (command === 'banword') {
if (!message.member.hasPermission("ADMINISTRATOR")) return message.channel.send("You can't use this command")
if (!args[0]) return message.channel.send("Choose either add or remove")
if (args[0] == 'add')
banWords.push(multipleArgs)
message.channel.send(banWordAdded)
console.log("Array updated");
} else if (args[0] == 'remove') {
delete banWords(multipleArgs)
message.channel.send(banWordRemoved)
console.log("Array updated")
添加禁止词时它工作得很好,但是当我想删除它时,机器人会删除包含禁止词的命令消息,而不是从 banWords 数组中删除它,就像我做 q!banword remove example 并且消息得到已删除
【问题讨论】:
标签: javascript node.js arrays discord.js