为什么我的前缀不起作用?- 不和谐.js V12.2.0



这是我的两个代码,它们在不同的文件夹中,我尝试的是嵌入中的消息可以与我的前缀一起使用,但是当我使用此命令时,我放在后面的字母,数字或符号无关紧要,因为无论前缀如何,该命令的执行方式都相同。

{
"token": "(my token)",
"prefix": "-"
}
const { Client, MessageEmbed } = require ("discord.js");
const client = new Client();
const MessageAttachment = require("discord.js");
const config = require("./config.json");
const Discord = require('discord.js');
const bot = new Discord.Client();
let prefix = config.prefix;
/////////////////BOT///////////////////
function doKissAction() {
var rand = [
'https://media2.giphy.com/media/G3va31oEEnIkM/giphy.gif',
'https://media.tenor.com/images/fbb2b4d5c673ffcf8ec35e4652084c2a/tenor.gif',
'https://media.giphy.com/media/ZRSGWtBJG4Tza/giphy.gif',
'https://media.giphy.com/media/oHZPerDaubltu/giphy.gif',
'https://acegif.com/wp-content/uploads/anime-kiss-m.gif',
'https://media.giphy.com/media/bm2O3nXTcKJeU/giphy.gif',
'https://media.giphy.com/media/nyGFcsP0kAobm/giphy.gif',
'https://media0.giphy.com/media/KH1CTZtw1iP3W/source.gif'
];
return rand[Math.floor(Math.random() * rand.length)];
}
client.on('message', message => {
let args = message.content.substring(prefix.length).split(" ");
switch (args[0]) {
case 'kiss':
if(!args[1] ) {
message.channel.send('¡Necesitas a alguien a quien besar!');
} else {
const personTagged = message.mentions.members.first();
const acceptedEmbed = new Discord.MessageEmbed()
.setTitle(':sparkles: :heart: ¡Que romantico! :heart: :sparkles: ')
.setImage(doKissAction())
.setColor(0xF086FF)
.setDescription('`' + message.author.username + '`' + ' ha besado a ' + '`' + personTagged.displayName + '`')
message.channel.send(acceptedEmbed);
//    personTagged.send();
}
break;
}
}) 

问题是您没有检查它是否以前缀开头,而只是删除了前缀

let args = message.content.split(" ");
let commandName = args[0];
if(!commandName.startsWith(prefix)) return;
commandName = commandName.slice(prefix.length);
switch(commandName) {
case 'kick': {
//..code
}
}

最新更新