在聊天Discord.js中留言dm

我似乎无法find如何让别人说!Dm,并只有去指定的播放器。 这是一个例子:

CoolGuy的信息:“!dm Moogstir Hello”

接收者(Moogstir):“-CoolGuy你好”

这是我的代码:

const Discord = require('discord.js'); const bot = new Discord.Client(); const Player = new Discord.Client(); bot.on('ready', () => { console.log(`It's an owl! It's a Bagel! NO It's a ${bot.user.tag}`) }); Player.on('message', (message) => { if (message.author.bot) return; const args = message.content.split(/ +/g); const command = args.shift().toLowerCase(); if(command === `!dm ` + `${player.user.tag}` + `${message.content}`) { message.Player.sendMessage(`-${message.author}` + "\n" + `${message.content}`); } }); 

要发送消息给消息的作者,使用message.reply(``);

如果您希望邮件转到作者以外的其他人,您需要获取收件人的ID /用户名,并将其传递到collections夹以查找它们。 例如: collection.find('username', 'myUsername');

此外, sendMessage折旧,如果您发送到您的服务器通道应该只是message.channel.send

您应该通读文档以了解基础知识。 其中一些可能一开始就让人困惑,但是随着它越来越多,它会开始变得有意义。

编辑:我不知道你为什么命名客户端player而不是clientbot ,但我会build议改变,以避免以后混淆。