discord.js - 如何获取添加机器人的用户?
问题描述
我目前正在开发 Discord.js 机器人,我希望获得将机器人添加到公会的用户的 ID 或名称。
我希望添加机器人的人得到一个 DM。
感谢您的回答!
解决方案
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.
});
});
推荐阅读
- javascript - 让 Redux 返回一个数组而不是嵌套对象
- ruby-on-rails - redis中rails缓存条目中的时间戳格式是什么?
- sql - 递归 CTE 性能不佳
- php - 生成大文件时如何解决 PHP 中的“分段失败”?
- sql - 在雪花中将 YYYYMMDD 转换为 MM/DD/YYYY
- swift - 有没有办法在 Xcode 中发表评论,以便在拉取请求中不显示?
- java - 返回从 String 的输入参数索引开始的字符串
- swift - not initialised at super.init swift
- javascript - 按设置的顺序获取所有本地存储项目
- xamarin.forms - Xamarin.Forms with Shell:有没有办法只为活动选项卡指定图标的颜色?