我正在尝试为服务器创建日志,因此当有人发送,删除或编辑消息时,机器人将在特定通道中发送包含所有信息的嵌入消息。由于某种原因,messageUpdate和messagedDelete事件被多次触发,我不明白为什么。我已经尝试了一切,但没有任何效果。为什么会发生这种情况,我该如何解决?
顺便说一句,我在单个文件中有每件事(发送,编辑,删除)的日志。在我的主文件中,这是我用于messageUpdate的代码:
bot.on('messageUpdate', (oldMessage, newMessage) => {
if (oldMessage.author.id === bot.user.id) return;
if(oldMessage.content === newMessage.content) return;
bot.events.get('editlogs').execute(oldMessage, newMessage);
})
这是我的编辑日志代码:
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.login(process.env.TOKEN);
module.exports = {
name: 'editlogs',
description: 'logs messages that were edited.',
category: 'logs',
execute(oldMessage, newMessage){
const logsChannel = bot.channels.cache.get("743142195594526822")
const logEmbed = new Discord.MessageEmbed()
.setColor('#ffa600')
.setTitle('Message Edited')
.setAuthor(oldMessage.author.tag, oldMessage.author.avatarURL())
.setThumbnail(oldMessage.author.avatarURL())
.addFields(
{ name: 'Old Message', value: oldMessage.content},
{ name: 'New Message', value: newMessage.content},
{ name: 'Channel', value: oldMessage.channel.toString(), inline: true },
{ name: 'Author', value: oldMessage.author, inline: true },
{ name: 'Author ID', value: oldMessage.author.id},
{ name: 'Message ID', value: oldMessage.id},
{ name: 'Message', value: '[Jump To Message](' + oldMessage.url + ')'},
)
.setTimestamp()
.setFooter('Edited in ' + oldMessage.guild.toString(), oldMessage.guild.iconURL());
logsChannel.send(logEmbed);
}}