javascript - DiscordAPIError: Unknown Message - Stack Overflow

I have made a freeze mand using discord.js and mando, that gives the user a role, and keeps them from t

I have made a freeze mand using discord.js and mando, 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.

Code:

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 mand!**`)
    message.delete(5000)
  }
}

Any help would be appreciated! Thanks.

I have made a freeze mand using discord.js and mando, 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.

Code:

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 mand!**`)
    message.delete(5000)
  }
}

Any help would be appreciated! Thanks.

Share Improve this question edited Apr 2, 2019 at 18:32 Federico Grandi 6,7865 gold badges33 silver badges51 bronze badges asked May 25, 2018 at 21:07 swoodsswoods 3732 gold badges5 silver badges12 bronze badges 1
  • You first delete the message and then grab everything from there? Doesn't seem right.. – André Commented May 25, 2018 at 22:02
Add a ment  | 

1 Answer 1

Reset to default 4

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()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743900666a4526585.html

相关推荐

  • javascript - DiscordAPIError: Unknown Message - Stack Overflow

    I have made a freeze mand using discord.js and mando, that gives the user a role, and keeps them from t

    2天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信