所以我正在研究discord.js票务系统,但遇到了一个我似乎无法自行修复的错误。
基本上,我会处理打开和关闭故障单的反应,但是如果有人制作了故障单,然后我重新启动了漫游器,则在重新启动之前创建的故障单将不起作用。 应该关闭票证的反应不会-但是它对 重置
之后制作的任何票证都有效我的代码:
else if(reaction.emoji.name === '?') {
if(userTickets.has(user.id)) {
if(reaction.message.channel.id === userTickets.get(user.id)) {
reaction.remove(user);
let embed = new RichEmbed();
embed.setDescription("Ticket will be closed in 5 seconds.")
reaction.message.channel.send(embed);
setTimeout(() => {
reaction.message.channel.delete('closing ticket')
.then(channel => {
console.log("Deleted " + channel.name);
})
.catch(err => console.log(err));
}, 5000);
}
}
else if(reaction.message.guild.channels.some(channel => channel.name.toLowerCase() === user.username + 's-ticket')) {
let embed = new RichEmbed();
embed.setDescription("Ticket will be closed in 5 seconds.");
reaction.message.channel.send(embed);
setTimeout(() => {
reaction.message.guild.channels.forEach(channel => {
if(channel.name.toLowerCase() === user.username + 's-ticket') {
channel.delete().then(ch => console.log('Deleted Channel ' + ch.id))
}
});
}, 5000);
}
}
});
答案 0 :(得分:0)
您必须处理未缓存邮件的事件
它在重新加载时不起作用的原因是因为每次重新启动bot时都会清除缓存。仅新消息将被缓存。反应事件不会在未加载的消息上触发。
要解决此问题,您将必须监听{ _id: 1, count: 4 }, { _id: 2, count: 2 }
事件。看起来像这样:
raw
我无法比ÉvelyneLachance在original guide i took this from中所做的解释更好,因此,如果您想了解它的工作原理,请在那里阅读。
此代码段将自动调用// check for reactions on unloaded messages and trigger the appropriate events
client.on('raw', packet => {
if (!['MESSAGE_REACTION_ADD', 'MESSAGE_REACTION_REMOVE'].includes(packet.t)) return;
const channel = client.channels.get(packet.d.channel_id);
if (channel.messages.has(packet.d.message_id)) return;
channel.fetchMessage(packet.d.message_id).then(message => {
const emoji = packet.d.emoji.id ? `${packet.d.emoji.name}:${packet.d.emoji.id}` : packet.d.emoji.name;
const reaction = message.reactions.get(emoji);
if (packet.t === 'MESSAGE_REACTION_ADD') { client.emit('messageReactionAdd', reaction, client.users.get(packet.d.user_id)); }
if (packet.t === 'MESSAGE_REACTION_REMOVE') { client.emit('messageReactionRemove', reaction, client.users.get(packet.d.user_id)); }
});
});
和messageReactionAdd
事件并传递必要的参数,因此,除了将其复制粘贴到主文件中之外,您实际上不需要做很多事情。 / p>