当人们创建时,我正在尝试创建discord.js机器人日志,并使用审核日志删除渠道。我有创建记录下来,但是删除部分给了我一个错误:“ UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性'name'”。我不知道为什么它不起作用。
我的频道删除记录代码:
bot.on("channelDelete", async() => {
var channeldeleteauditlogs = await bot.guilds.find(g => g.id === '621810400924794890').fetchAuditLogs({
type: 11
});
let entry = channeldeleteauditlogs.entries.first();
var channeldeletelog = fs.readFileSync('channeldeletelog.txt', 'utf-8');
var channeldeletelog2 = fs.writeFileSync('channeldeletelog.txt', '\nTime - ' + entry.createdAt.toUTCString() + ' | Channel - ' + entry.target.name + ' | User - ' + entry.executor.username + ' (' + entry.executor.id + ')' + channeldeletelog);
console.log(entry.executor.username + " deleted a channel");
});
(成功的)我的频道创建记录代码:
bot.on("channelCreate", async() => {
let channelcreateauditlogs = await bot.guilds.find(g => g.id === '621810400924794890').fetchAuditLogs({
type: 10
});
let entry = channelcreateauditlogs.entries.first();
var channelcreatelog = fs.readFileSync('channelcreatelog.txt', 'utf-8');
var channelcreatelog2 = fs.writeFileSync('channelcreatelog.txt', '\nTime - ' + entry.createdAt.toUTCString() + ' | Channel - ' + entry.target.name + ' (' + entry.target.id + ') | User - ' + entry.executor.username + ' (' + entry.executor.id + ')' + channelcreatelog);
console.log(entry.executor.username + " created a channel");
});
谢谢。
答案 0 :(得分:1)
您可以尝试使用channel
事件随附的channelDelete
参数。
bot.on("channelDelete", async (channel) => {
console.log(channel.name)