DiscordAPIError:未知消息 [英] DiscordAPIError: Unknown Message

查看:155
本文介绍了DiscordAPIError:未知消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用discord.js和commando发出了冻结命令,该命令赋予用户角色,并防止他们交谈和聊天。似乎每次运行它都会抛出一个错误:

I have made a freeze command using discord.js and commando, that gives the user a role, and keeps them from talking and chatting. It seems that every time I run it though, it tosses an error:

(node:7352) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Message

我无法找到它是什么,但也许我只是个小结。

I haven't been able to find what it is, but maybe i'm just a nub.

代码:

async run(message, { user }) {
  message.delete()

  const member = message.guild.member(user);

  if (!message.member.hasPermission("MUTE_MEMBERS")) return message.say("Sorry, but you do not have the Mute Members Permission! If you beleive this is a error, contact an owner.");

  if (!user) return message.say(`Cannot find user!`)

  if (member.hasPermission("MUTE_MEMBERS")) return message.say("The user you are trying to freeze is either the same, or higher role than you.");

  let muterole = message.guild.roles.find(`name`, "Frozen");

  if (member.roles.has(muterole)) return message.say(`${user.username} is already frozen!`);

  if (!muterole) {
    try {
      muterole = await message.guild.createRole({
        name: "Frozen",
        color: "#000000",
        permissions: []
      })
      message.guild.channels.forEach(async(channel, id) => {
        await channel.overwritePermissions(muterole, {
          SEND_MESSAGES: false,
          ADD_REACTIONS: false,
          SPEAK: false
        });
      });
    } catch (e) {
      console.log(e.stack);
    }

    await (member.addRole(muterole.id))
    message.say(`**${user.username} has been frozen! To unfreeze them, use the unfreeze command!**`)
    message.delete(5000)
  }
}

任何帮助将不胜感激!谢谢。

Any help would be appreciated! Thanks.

推荐答案

我认为这是由于您删除带有 message的消息所致。在第一行中删除(),但最后使用 message.delete(5000)再次执行。
其余代码运行良好,因为即使您删除了该消息,该消息仍保存在 message 变量中,但是当您再次尝试删除该API时,找不到它。尝试删除其中一个 message.delete()

I think that's caused by the fact that you're deleting the message with message.delete() in the first lines, but at the end you do that again with message.delete(5000). The rest of the code runs fine because even if you deleted the message it's still saved in your message variable, but when you try to delete that again the API isn't able to find it. Try removing one of the message.delete()

这篇关于DiscordAPIError:未知消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆