【问题标题】:Trying to make a bot that sends DMs to users试图制作一个向用户发送 DM 的机器人
【发布时间】:2019-09-07 17:44:58
【问题描述】:

我正在尝试制作一个不和谐的机器人来检查在频道中发送的消息的前缀和参数(!发送@Usermention“消息”),但尽管运行,程序在我输入消息后立即关闭不和谐的服务器,没有输出任何错误信息,所以我不太确定该怎么做......

       const Discord = require('discord.js');
       const client = new Discord.Client();
       const auth = require('./auth.json');
       const prefix = "!";

       client.on("message", (message) => 
       {
           msg = message.content.toLowerCase();

           if (message.author.bot) { return; }
           mention = message.mention.users.first(); //gets the first mention of the user's message

           if (msg.startsWith (prefix + "send")) //!send @name [message]
           {
               if (mention == null) { return; } //prevents an error sending a message to nothing
               message.delete();
               mentionMessage = message.content.slice (6); //removes the command from the message to be sent
               mention.sendMessage (mentionMessage); //sends message to mentioned user
               message.channel.send ("message sent :)");
           }
       });
       client.login(auth.token);

【问题讨论】:

  • 如果您想查看任何错误,请将您正在运行的内容包装在 try catch 块中

标签: javascript bots discord discord.js


【解决方案1】:

mention = message.mention.users.first();
它是message.mention**s**。你错过了s

此外,您可能希望使用send,而不是sendMessage,因为sendMessage 已被弃用。

【讨论】:

  • +1 我非常感谢,我不知道我做错了什么。我最初使用的是 .send,但由于它不起作用,我认为它可能是 sendmessage。对此进行测试后,我发现它有效。谢谢你:)
猜你喜欢
  • 2021-12-23
  • 2019-06-27
  • 2022-08-11
  • 2019-02-19
  • 2021-06-13
  • 2020-08-22
  • 2022-10-13
  • 2020-12-28
  • 2021-12-03
相关资源
最近更新 更多