简体   繁体   中英

My discord bot is ignoring commands that have capital letters in them

So I'm trying to put together a bot, and I've found that for whatever reason, it doesn't respond to any commands that have capital letters in them. And by that I mean it has defined commands that have capital letters in them, but the bot won't actually run the code in the commands that have capital letters. I have my commands defined in a switch/case that I've entered below, which uses properties of an object passed to the commands file from the main file.

switch (command.call) {
  case 'ping':
    message.reply(`Pong! This message had a latency of ${latency}ms.`);
  console.log(`Received message $ping, responded with latency of ${latency}ms.`);
    break;

  case 'help':
    message.reply('Current commands available:\n  \`$ping\`: Get the latency of the bot.\n  \`$help\`: Show this message.\n  \`$setPrefix\` \`[arg]\`: Set the prefix to a given string, \`[arg]\`');
    console.log(`Received message $help, responded with latency of ${latency}ms.`);
    break;

  case 'setPrefix':
    message.reply(`Set the new prefix to ${config.prefix}`);
    console.log(`Received message $setPrefix, responded with latency of ${latency}ms.`);
    break;

  case 'Test':
    message.reply('I got your message!');
  console.log(`Received message $test, responded with latency of ${latency}ms.`);
    break;
  }
}

So the commands ping and help work correctly, but the bot doesn't do anything when I try to call setPrefix or Test .

This is my code that passes the command to the file that defines the commands:

  commandBody = message.content.slice(config.prefix.length), //Get the body of the command
  args = commandBody.split(' '), //Get the command arguments
  call = args.shift().toLowerCase() //Get the command

  const command = {
    commandBody: commandBody,
    args: args,
    call: call
  }

  commands(command, message); //Call the given command from commands.js

That last line that calls commands() is referencing the file that defines the commands for the bot

Add to your code .toLowerCase()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM