首页 > 解决方案 > 如何获取添加机器人的用户?

问题描述

我目前正在开发 Discord.js 机器人,我希望获得将机器人添加到公会的用户的 ID 或名称。

我希望添加机器人的人得到一个 DM。

感谢您的回答!

标签: discord.js

解决方案


client.on("guildCreate", guild => { // This event fires when a guild is created or when the bot is added to a guild.
    guild.fetchAuditLogs({type: "BOT_ADD", limit: 1}).then(log => { // Fetching 1 entry from the AuditLogs for BOT_ADD.
        log.entries.first().executor.send(`Thank you for adding me to ${guild.name}!`).catch(e => console.error(e)); // Sending the message to the executor.
    });
});

推荐阅读