В своем коде вы не проверяете, начинается ли сообщение с вашего префикса.Итак, ваш код выполняется для каждого сообщения, и если команда находится после подстроки одинаковой длины PREFIX
, она вызовет команду.
Исправленный код:
// Example prefix.
const PREFIX = '!';
bot.on('message', message => {
// Ignore the message if it's from a bot or doesn't start with the prefix.
if (message.author.bot || !message.content.startsWith(PREFIX)) return;
// Take off the prefix and split the message into arguments by any number of spaces.
const args = message.content.slice(PREFIX.length).split(/ +/g);
// Switching the case of the command allows case iNsEnSiTiViTy.
switch(args[0].toLowerCase()) {
case 'yeet':
message.channel.send('yeet')
// Make sure to handle any rejected promises.
.catch(console.error);
break;
}
});