【问题标题】:Is there a way to send a message to a specific user in the bot.on("ready") function?有没有办法在 bot.on("ready") 函数中向特定用户发送消息?
【发布时间】:2019-12-21 05:30:33
【问题描述】:

我正试图让我的机器人在上线/准备就绪时向我发送直接消息

我尝试过使用bot.guilds.members.find("id", "my id")等函数 和bot.guilds.members.get("id", "my id") 但它只是返回 find/get is not a function

bot.on("ready", async message => {
    bot.guilds.members.find("id", "my id") 
});

我希望机器人在线时向我发送消息

【问题讨论】:

  • 我需要它在启动时执行此操作,但不是在消息上,而且您无法在启动时从消息中收集公会

标签: javascript discord.js


【解决方案1】:
bot.on("ready", async () => {
    bot.users.get("Your ID").send("Message")
});

【讨论】:

  • 我只是得到“无法读取未定义的属性'通道'的错误
  • 在您的代码 sn-p 中,async 不是多余的,未提供的message 参数总是未定义吗?
  • 也许他用它来做别的事
【解决方案2】:

ready event 没有提供任何参数(我希望这是正确的表达方式)。所以你的回调函数的message 参数是undefined,并且尝试读取message.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");
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 2023-03-27
    • 2017-03-24
    • 2021-07-23
    • 2021-08-22
    相关资源
    最近更新 更多