简体   繁体   中英

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.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). 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.

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");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM