尝试制作将DM发送给用户的机器人

时间:2019-09-07 04:03:44

标签: javascript bots discord discord.js

我正在尝试创建一个不和谐的bot,以检查在通道中发送的消息的前缀和参数(!send @Usermention“ message”),但是尽管运行了,但只要在我的计算机中键入消息,程序就会关闭不和谐的服务器,不输出任何错误消息,所以我不太确定该怎么做...

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

1 个答案:

答案 0 :(得分:0)

mention = message.mention.users.first();
message.mention**s**。您错过了s

此外,由于不推荐使用sendMessage,因此您可能想使用send而不是sendMessage