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

时间:2018-01-23 12:50:16

标签: node.js discord discord.js

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

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

这是我的代码:

文件名: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

有没有办法忽视它已经离开并完全忽略它的事实?

1 个答案:

答案 0 :(得分:1)

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

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。当然,还有其他方法可以做到这一点,但这听起来像是库和缓存的错误。如果这导致任何进一步的错误,并且上述问题无法解决问题,请尝试在Discord上更详细地报告问题(以查找并识别错误)。从那里,如果它确实是一个bug,他们会指示你向他们的GitHub报告。快乐的编码!