【问题标题】:I was making a Discord bot...... and i keep geting this error我正在制作一个不和谐的机器人......我一直收到这个错误
【发布时间】:2021-08-19 07:10:55
【问题描述】:

我正在使用“禁止”命令 (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})

【问题讨论】:

  • 您是否在switch 中使用case 语句?

标签: discord bots


【解决方案1】:

你错过了一个括号。

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 语句之前检查 - 这就是问题所在。

【讨论】:

  • 我看不到您的完整代码。也许您的switch 丢失或没有命名方法ban
猜你喜欢
  • 2021-05-03
  • 1970-01-01
  • 2021-07-24
  • 1970-01-01
  • 2023-01-05
  • 2022-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多