[英]Is there a way to send a message to a specific user in the bot.on("ready") function?
I'm trying to get my bot to send me a direct message when it gets online/is ready我正在尝试让我的机器人在它上线/准备好时向我发送直接消息
I've tried to use functions such as bot.guilds.members.find("id", "my id")
and bot.guilds.members.get("id", "my id")
but it just returns find/get is not a 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")
});
I want the bot to send me a message when it comes online我希望机器人在上线时向我发送消息
bot.on("ready", async () => {
bot.users.get("Your ID").send("Message")
});
The ready event does not provide any arguments (I hope that's the right way to phrase that). ready 事件不提供任何参数(我希望这是正确的表达方式)。 So your callback function's
message
parameter is undefined
, and attempting to read message.channel
gives you that "cannot read property 'channel' of undefined" error.因此,您的回调函数的
message
参数是undefined
,并且尝试读取message.channel
会给您“无法读取未定义的属性 'channel'”错误。
This should work:这应该有效:
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.