如何让机器人找到频道所有者/与作者的 ID 进行比较

How to make a bot find a channel owner / compare to the author's ID

我正在制作一个机器人,如果您这样做 d!move,机器人将通过 ID 将发送消息的频道移动到一个类别下。我还想使执行命令的人都拥有我已经添加的 MANAGE_CHANNELS 等权限。问题是,当我想确认创建该频道的人就是激活命令的人时,机器人说是。我是在一个 alt 帐户上做的,在那里我创建了频道,我的 alt 是初始化它的那个,机器人说 "success!" 我也想这样做,所以如果其他人创建了频道,我什么时候做的,它会起作用,因为我让机器人知道我的 ID。

我研究过 Google 但一无所获。

我试过将函数与 fetchAuditlog 一起使用,但无济于事。

    if(!message.channel.client.user.id == message.author || !message.author.id == `329023088517971969`) return message.channel.send("You don't own this channel!")
    else message.channel.send("success!"); 
    message.channel.setParent(`576976244575305759`);

我希望机器人能够检查作者是否创建了频道,如果他们不拥有频道,则会导致 You don't own this channel。但如果他们这样做了,那么机器人就会移动频道。

实际结果是无论是否拥有频道,机器人都会移动频道。

当您进入 <anything>.client.user 时,它将 return 机器人客户端。
如果您想查看谁创建了频道,则必须检查审核日志或将其保存在内部。

I've checked the documents. Here's what it says for .client about the channel. It says the person that initialized the channel, or the person that created it.

On documentation I see this:

The client that instantiated the Channel

instantiated 不同于 initialized

正如 @André 指出的那样,channel.client 代表客户本身,而不是创建频道的用户。此外,代码中的最后一行不是 else 语句的一部分,因此无论您定义的条件如何,它都是 运行 的原因。

要找到解决方案,您可以利用公会的审核日志。您可以搜索用户是消息作者并且创建了频道的条目。然后,您剩下的就是检查这些条目之一是否适用于当前频道,如果是,运行 您的其余代码。

样本:

message.guild.fetchAuditLogs({
  user: message.author,
  type: 'CHANNEL_CREATE'
}).then(logs => {
  if (!logs.entries.find(e => e.target && e.target.id === message.channel.id)) return message.channel.send('You don\'t own this channel.');
  else {
    // rest of code
  }
}).catch(err => console.error(err));