我想找到给机器人发消息的人的用户 ID。有什么办法吗?我正在使用 Discord.js,我尝试通过存储成员作者和成员 ID,但它没有用。但是当我存储频道时,它会将其存储为作者标签。但是该频道的 id 与 DM 机器人的用户的 id 不匹配。我正在尝试制作支持邮件机器人。但它需要用户 ID,以便我可以通过 DMing 用户来继续线程。但在我获得用户 ID 或服务器成员对象之前,这是不可能的。而且我无法将该 DMchannel 存储在我的数据库中,因为我使用 json 来存储数据。
问问题
3111 次
2 回答
2
由于我的声誉低下,我无法发表评论,如果这不能回答您的问题,我很抱歉。
您可以通过 DM 获取您的机器人的人的 ID message.author.id
(请记住,message
需要更改为您的消息存储在其中的任何变量)。
您还可以使用 获取频道 ID message.channel.id
。
频道 ID 与用户 ID 不同(它们是两个不同的东西),我假设您从id for that channel does not matchs with the id of the user who DM the bot
.
于 2019-04-29T15:00:55.887 回答
1
尝试这个:
const client = new discord.Client();
client.login('token here');
/* On message event since you want to
* recieve DM and get ID from user who sent DM to your bot.
*/
client.on("message", (msg) => {
// checks if the message's channel type is 'DM'.
if(msg.channel.type === "dm") {
// you can do anything you want here. In my case I put console.log() function.
// since you wanted user ID, you can use msg.author.id property here.
console.log(`Recieved DM from ${msg.author.tag}, DM content is`, msg.content);
}
});
请记住,作者/会员 ID 和 dm 消息频道 ID 是完全独立的东西。
在 JSON 或 SQL 中存储成员相关数据也不是一个好主意。我建议您只对您生成的自定义数据执行此操作,否则会浪费大量内存。
于 2020-05-05T09:04:09.953 回答