【问题标题】:roleDelete event having problems after leaving guild离开公会后的角色删除事件有问题
【发布时间】:2018-07-02 07:14:34
【问题描述】:

这个错误是在我向公会发送消息后添加.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

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

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    这听起来像是多个事件异步运行的错误。如果是这种情况,简单检查客户是否仍在公会中应该可以解决问题。可以在下面找到执行此操作的几种方法中的一种示例。

    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 上更详细地报告问题(以查找和识别错误)。从那里,如果它确实是一个错误,他们会指导你向他们的 GitHub 报告。编码愉快!

    【讨论】:

    • 谢谢,它完全有效。我实际上已经在我的脑海中进行了修复并之前部署过。但不知道它也是那个错误的补丁!还是谢谢你:D
    猜你喜欢
    • 2021-04-29
    • 2020-09-27
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    • 1970-01-01
    • 2021-04-30
    相关资源
    最近更新 更多