Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.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 Discord.JS |如何使用**channel.client**功能而不显示bot客户端信息?_Javascript_Bots_Discord_Discord.js - Fatal编程技术网

Javascript Discord.JS |如何使用**channel.client**功能而不显示bot客户端信息?

Javascript Discord.JS |如何使用**channel.client**功能而不显示bot客户端信息?,javascript,bots,discord,discord.js,Javascript,Bots,Discord,Discord.js,我试图在我的机器人上使用Discord.js上的ChannelUpdate事件,当频道更新时,我记录频道的旧信息,如名称、id、类型、创建者等,然后记录频道的更新信息。其他一切正常,但当我尝试使用channel.client.user.username获取频道的创建者时,它最终显示的是机器人的用户名。我该如何解决这个问题?代码如下 const Discord=require('Discord.js'); const bot=new Discord.Client(); bot.on('ready'

我试图在我的机器人上使用Discord.js上的ChannelUpdate事件,当频道更新时,我记录频道的旧信息,如名称、id、类型、创建者等,然后记录频道的更新信息。其他一切正常,但当我尝试使用channel.client.user.username获取频道的创建者时,它最终显示的是机器人的用户名。我该如何解决这个问题?代码如下

const Discord=require('Discord.js');
const bot=new Discord.Client();
bot.on('ready',()=>{
console.log(`${bot.user.username}现在已联机!`)
});
//频道更新事件---
bot.on('channelUpdate',oldChannel=>{
console.log(`oldChannel.name}已在${oldChannel.guild.name}中更新。频道信息如下:`);
log(`Channel Name Before:${oldChannel.Name}`);
log(`Channel ID Before:${oldChannel.ID}`);
log(`Channel Creator Before:${oldChannel.client.user.username}`);
log(`Channel Type Before:${oldChannel.Type}`);
log(`Channel createdAt}`之前的频道创建日期:${oldChannel.createdAt}`);
log(`Channel Name Now:${Channel.Name}`);
log(`Channel ID Now:${Channel.ID}`);
log(`channelcreatornow:${guild.Channel.client.user}`);
log(`Channel-Type Now:${Channel.Type}`);
log(`Channel Creation Date Now:${Channel.createdAt}`);
});

就我而言,任何东西上的
客户端
属性都只会显示您自己的bot客户端,因为它是bot的客户端,通过与Discord通信来检索频道和行会之类的东西。除此之外,访问任何其他用户的客户端都太危险了(想象一下,通过访问他们的
client.token
,您可以做些什么)


对于你在这里的情况,你可以通过获取公会的审计日志来找出谁更新了频道。是指向有关
Guild.fetchAuditLogs()
的文档的链接

医生说你需要旧频道和新频道

client.on("channelUpdate", async (oldChannel, newChannel) => { 

    console.log(`${oldChannel.name} has been updated in ${oldChannel.guild.name} the info for the channel is below:`);
    console.log(`Channel Name Before: ${oldChannel.name}`);
    console.log(`Channel ID Before: ${oldChannel.id}`);
    console.log(`Channel Creator Before: ${oldChannel.client.user.username}`);
    console.log(`Channel Type Before: ${oldChannel.type}`);
    console.log(`Channel Creation Date Before: ${oldChannel.createdAt}`);

    console.log(`Channel Name Now: ${newChannel.name}`);
    console.log(`Channel ID Now: ${newChannel.id}`);
    console.log(`Channel Creator Now: ${newChannel.guild.channel.client.user}`);
    console.log(`Channel Type Now: ${newChannel.type}`);
    console.log(`Channel Creation Date Now: ${newChannel.createdAt}`);

});

这应该是您要查找的信息。

我不是这样想的,但您完全正确。谢谢你的帮助链接。