Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何将我的机器人的dm登录到其他服务器?|Discord.js_Node.js_Discord.js - Fatal编程技术网

Node.js 如何将我的机器人的dm登录到其他服务器?|Discord.js

Node.js 如何将我的机器人的dm登录到其他服务器?|Discord.js,node.js,discord.js,Node.js,Discord.js,我正在尝试将我的bot的dm登录到其他服务器。我怎么能这么做?我正在使用V12 discord.js 这是我的密码 let channelID = "722595878636XX3XX5"; let guildID = "722595878636XX3XX1"; if(message.channel.type === `dm`){ let embed = new Discord.RichEmbed() .setAuthor(client.guilds.cache.get(

我正在尝试将我的bot的dm登录到其他服务器。我怎么能这么做?我正在使用V12 discord.js

这是我的密码

let channelID = "722595878636XX3XX5";
  let guildID = "722595878636XX3XX1";
  if(message.channel.type === `dm`){
    let embed = new Discord.RichEmbed()
    .setAuthor(client.guilds.cache.get(guildID).members.cache.get(message.author.id).displayName)
    .setColor('#7ED321')
    .setDescription(message.content);
    client.channels.cache.get(channelID).send(embed);
  }

基本上,如果你想这么做:

const{Client,MessageEmbed}=require'discord.js'; const客户端=新客户端; client.onmessage,异步消息=>{ 如果!message.guild{//如果没有公会,则这是一个DM var embed=new MessageEmbed//为v12创建新的嵌入使用MessageEmbed .setTitle`DM从${message.author.tag}${message.author.id}接收` .setDescriptionmessage.content .设置时间戳; var channel=client.channels.cache.getChannelID;//获取通道 channel.sendembed;//发送嵌入 } };
@S0me0n3-1您使用的是Discord JS V12还是V11?我可以看看你的全部代码吗?
client.on("message", (message) => {
    if (!message.guild) { // DM Message
        const Embed = new discord.MessageEmbed(); // In V12 RichEmbed changed to MessageEmbed;
        const Channel = client.channels.cache.get("ChannelID");
        Embed.setAuthor(`Private Message from ${message.author.tag}`, message.author.avatarURL()); // In V12 avatarURL is a method;
        Embed.setColor("#7ED321");
        Embed.setDescription(message.content);
        if (!Channel) {return console.error(`Invalid Channel`)};
        Channel.send(Embed);
    };
});