离开公会后角色删除事件有问题

roleDelete event having problems after leaving guild

我在向公会发送消息后向 Promises 添加了 .catch 语句后出现此错误。

快速说明:我的机器人正在尝试从它不再属于的公会中检索数据。

这是我的代码:

文件名:roleDelete.js

'use strict';

const Discord = require('discord.js');
const Error = require('debug')('Event:roleDelete:Error');

/**
 * @param {object} client - The client instance
 * @param {object} role - The deleted role object
*/

module.exports.run = (client, role) => {
  let embed = new Discord.RichEmbed();
  const guildID = role.guild.id;
  const guildName = role.guild.name;
  const guildIcon = role.guild.iconURL;
  const modLog = client.guilds.get(guildID).channels.find('name', client.config.modLog);
  const tempIcon = 'https://images-ext-2.discordapp.net/external/ouGhEoGzz1ZyBG9mMFrYClvdv9V0FZ0jGSEHa_kLLYk/https/discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png';

  if (!modLog) return;

  embed = new Discord.RichEmbed()
    .setAuthor(guildName, guildIcon ? guildIcon : tempIcon)
    .addField('Role Name', role.name, true)
    .addField('Role Color', role.hexColor, true)
    .addField('Role Hoisted', role.hoist, true)
    .setFooter('Role Deleted At')
    .setTimestamp()
    .setColor(client.config.colors.red);

  return modLog.send(embed).catch(err => Error(err));
};

附加信息:

bufferutil: 3.0.3
chalk: 2.3.0
clear: 0.0.1
debug: 3.1.0
discord.js: 11.3.0
dotenv: 4.0.0
firebase-admin: 5.8.1
moment: 2.20.1
opusscript: 0.0.6

预期结果:

Discord.JS ignores and no error is thrown.

当前结果:

2018-01-23T12:34:05.029Z Event:guildDelete Left Guild: 395928739201941506, removed into database. 
2018-01-23T12:34:05.212Z Event:roleDelete:Error DiscordAPIError: Missing Access 
     at item.request.gen.end (/app/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:71:65) 
     at then (/app/node_modules/snekfetch/src/index.js:218:21) 
     at <anonymous> 
     at process._tickCallback (internal/process/next_tick.js:188:7) 
2018-01-23T12:34:05.255Z Event:guildMemberRemove:Error DiscordAPIError: Missing Access 
     at item.request.gen.end (/app/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:71:65) 
     at then (/app/node_modules/snekfetch/src/index.js:218:21) 
     at <anonymous> 
     at process._tickCallback (internal/process/next_tick.js:188:7

有什么办法可以忽略它已经离开的事实,完全忽略它吗?

这听起来像是多个事件 运行 异步发生的错误。如果是这种情况,只需检查客户是否仍在公会中即可解决问题。可以在下面找到 几种方法中的一个示例。

const guild = bot.guilds.get(myguildid); // Should return null if the guild is not found
if (!guild) // The guild does not exist.

使用的属性可以找到here in the documentation. Of course, there are other ways to do this, but this also sounds like a bug with the library and caching. If this causes any further bugs and the above does not fix the issue, try reporting the issue in more detail on the Discord(查找和识别bug)。从那里,如果确实是一个错误,他们会指示您将其报告给他们的 GitHub。编码愉快!