Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何找到不和谐频道的创建者?_Javascript_Node.js_Discord_Bots_Discord.js - Fatal编程技术网

Javascript 如何找到不和谐频道的创建者?

Javascript 如何找到不和谐频道的创建者?,javascript,node.js,discord,bots,discord.js,Javascript,Node.js,Discord,Bots,Discord.js,当涉及到通过不一致审计日志获取操作时,我是一个新手;所以我正在试验,不知怎么地想出了这个代码。但是,当我创建一个频道时,它不会发送任何消息说频道是由@user创建的。我不知道我的下一步是什么。我只想知道是谁创造了这个频道 Discord.JS:v12.2.0client.on(“channelCreate”,异步通道=>{ 如果(!channel.guild)返回false;//这是一个DM频道。 const AuditLogFetch=wait channel.guild.fetchAudit

当涉及到通过
不一致审计日志获取操作时,我是一个新手;所以我正在试验,不知怎么地想出了这个代码。但是,当我创建一个频道时,它不会发送任何消息说频道是由
@user
创建的。我不知道我的下一步是什么。我只想知道是谁创造了这个频道

Discord.JS:
v12.2.0

client.on(“channelCreate”,异步通道=>{
如果(!channel.guild)返回false;//这是一个DM频道。
const AuditLogFetch=wait channel.guild.fetchAuditLogs({limit:1,键入:“channel_CREATE”});//获取audot日志。
const LogChannel=client.channels.cache.get(“722052103060848664”);//获取loggin通道。(确保它是TextChannel)
if(!LogChannel)返回console.error(`Invalid channel.`);//检查通道是否存在。
if(!AuditLogFetch.entries.first())返回console.error(`No entries found.`);
const Entry=AuditLogFetch.entries.first();//获取找到的第一个AuditLogs条目。
LogChannel.send(`${Entry.executor.tag | | | |“Someone”}创建了一个新通道。${channel}`//将消息发送到日志通道。
});


如果我提供的代码不起作用,请确保bot有权查看AuditLogs。

控制台中有错误吗?@Jakye没有,我没有错误。我忘了添加
try…catch
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.`);
    }
});