简体   繁体   English

有没有办法在 bot.on("ready") 函数中向特定用户发送消息?

[英]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.

相关问题 TypeError:bot.on不是函数 - TypeError: bot.on is not a function 如何在 bot.on('ready', () => { }) 函数内的 discord.js 中获取频道 ID - How can I get a channel id in discord.js inside of the bot.on('ready', () => { }) function DiscortJS 机器人在提及特定用户的频道上发回消息 - DiscortJS bot send a message back on the channel mentioning a specific user 准备好/启动时向特定频道发送消息 - send message to specific channel upon ready/launch 当特定用户玩特定游戏时,如何让我的不和谐机器人发送消息? - How do I make my discord bot send a message when a specific user plays a specific game? 如何使用 discord 机器人将消息发送到特定通道? - How to send message to a specific channel with discord bot? 使不和谐机器人发送消息特定通道 - make discord bot to send message specific channel bot.on('messageCreate') discord.js 如何工作? 机器人不会检测到发送的消息,试图制作一个 discord 聊天机器人 - how dose the bot.on('messageCreate') discord.js work? the bot wont detect a sent message, trying to make a discord chat bot 当提到特定用户时,如何让不和谐机器人发送消息? - How do i make a discord bot send a message when a specific user is mentioned? 如何让我的 discord 机器人仅在用户开始输入特定频道时发送消息? - How can I make my discord bot only send a message if a user starts typing in a specific channel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM