[英]Is there a way to send a message to a specific user in the bot.on("ready") function?
我正在尝试让我的机器人在它上线/准备好时向我发送直接消息
我尝试使用bot.guilds.members.find("id", "my id")
和bot.guilds.members.get("id", "my id")
等bot.guilds.members.get("id", "my id")
但它只返回 find/ get 不是函数
bot.on("ready", async message => {
bot.guilds.members.find("id", "my id")
});
我希望机器人在上线时向我发送消息
bot.on("ready", async () => {
bot.users.get("Your ID").send("Message")
});
ready 事件不提供任何参数(我希望这是正确的表达方式)。 因此,您的回调函数的message
参数是undefined
,并且尝试读取message.channel
会给您“无法读取未定义的属性 'channel'”错误。
这应该有效:
const Client = new Discord.Client();
Client.login("YOUR TOKEN");
Client.on("ready", async () => {
let botDev = await Client.fetchUser("YOUR ID");
botDev.send("YOUR PRIVATE MESSAGE");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.