首页 > 解决方案 > 我正在制作一个不和谐的机器人......我一直收到这个错误

问题描述

我正在使用“ban”命令(discord.js)制作一个不和谐的机器人,但我不断收到此错误.... [解析错误意外令牌案例]

剧本:

    case 'ban': {
      if (!isMod)
        return;

      let userID = args.includes('<@!') ? args.replace('<@!', '').replace('>', '')
          : args.includes('<@') ? args.replace('<@', '').replace('<', '') : '';

      if (userID == '') {
        message.reply('Invalid user ID or mention.');
        return;
      }

      message.guild.fetchMember(userID).then(member => {
        member.kick("Banned by " + message.author.tag).then(m => {
          message.channel.send(' Banned <@' + userID + '>.');
        }).catch(() => {
          console.error;
          message.reply('Could not ban the specified member.');
        });
      };
      break;
    });

User.ban({reason: banReason})

标签: discordbots

解决方案


你错过了一个括号。

case 'ban': {
    if (!isMod)
        return;

    let userID = args.includes('<@!') ? args.replace('<@!', '').replace('>', '')
        : args.includes('<@') ? args.replace('<@', '').replace('<', '') : '';

    if (userID == '') {
        message.reply('Invalid user ID or mention.');
        return;
    }

    message.guild.fetchMember(userID).then(member => {
        member.kick("Banned by " + message.author.tag).then(m => {
            message.channel.send(' Banned <@' + userID + '>.');
        }).catch(() => {
            console.error;
            message.reply('Could not ban the specified member.');
        });
    });
    break;
}

在 break 语句之前检查 - 这就是问题所在。


推荐阅读