javascript - 如何获取不和谐频道的创建者?
问题描述
bot.on('channelCreate', async channel => {
if (!channel.guild) return;
const fetchedLogs = await channel.guild.fetchAuditLogs({
limit: 1,
type: 'CHANNEL_CREATE',
});
const logbook = channel.guild.channels.cache.get("ChannelID")
const deletionLog = fetchedLogs.entries.first();
if (!deletionLog) return logbook.send(`A channel was updated but no relevant autid logs were found`);
const { executor, user } = deletionLog;
if (user.id) {
logbook.send(`${executor.tag} created a channel`);
} else {
logbook.send(`A channel was created but idk who did.`);
}
});
在通过以下方式获取操作时,我是一个新手Discord Audit Logs
;所以我正在试验,并以某种方式想出了这段代码。但是,当我创建频道时,它不会发送任何消息说频道已由@user
. 我不知道我的下一步是什么。我只想知道是谁创建了这个频道。
不和谐.JS:v12.2.0
解决方案
client.on("channelCreate", async channel => {
if (!channel.guild) return false; // This is a DM channel.
const AuditLogFetch = await channel.guild.fetchAuditLogs({limit: 1, type: "CHANNEL_CREATE"}); // Fetching the audot logs.
const LogChannel = client.channels.cache.get("722052103060848664"); // Getting the loggin channel. (Make sure its a TextChannel)
if (!LogChannel) return console.error(`Invalid channel.`); // Checking if the channel exists.
if (!AuditLogFetch.entries.first()) return console.error(`No entries found.`);
const Entry = AuditLogFetch.entries.first(); // Getting the first entry of AuditLogs that was found.
LogChannel.send(`${Entry.executor.tag || "Someone"} created a new channel. | ${channel}`) // Sending the message to the logging channel.
});
如果我提供的代码不起作用,请确保机器人有权查看 AuditLogs。
推荐阅读
- oracle - 报告需要数小时才能显示数据并返回 0 条记录
- django - 由于 ec2 服务器中的 EnvironmentError 无法安装软件包
- vba - 是否可以将 Excel 图表的格式选项提取到 VBA 代码中?
- sql - Amazon Redshift:公共假期表的重复日期
- sql - SSRS表达式多条件
- javascript - jQuery on change 总是打印相同的值
- plugins - gitbook favicon插件不起作用
- influxdb - 删除所有系列与下降测量
- javascript - 有什么方法可以在使用 Express Generator 构建的 NodeJS API 上调试 UnhandledPromiseRejectWarning?
- three.js - 三.js fbxloader 示例 99% 成功