【发布时间】:2021-05-03 16:14:20
【问题描述】:
我正在尝试为我的 discord 机器人创建更详细的控制台日志,并且我想记录该机器人可以看到的所有消息。到目前为止我是这样做的:
client.on('message', message => {
const User = client.users.cache.get(message.author.id); // Getting the user by ID.
const Channel = client.channels.cache.get(message.channel.id); //getting the channel ID
console.log(User.tag + " in " + message.channel + " of " + message.guild + " said: " + message.content);
// rest of my code
});
client.login(token);
我能够弄清楚如何将用户 ID 转换为用户名,但我无法对频道 ID 和服务器 ID 做同样的事情。我通过对频道的用户名使用相同的代码,对频道 ID 尝试了类似的方法,但它仍然给了我数字。
在控制台中,如下所示:
Kingamezz#0218 in 763786268181397527 of 763786268181397524 said: message text
我的目标是尝试将 ID 转换为正确的名称,因此我得到的结果如下所示:
Kingamezz#0218 in #general of Testing Server said: message text
【问题讨论】:
标签: javascript node.js discord discord.js