如何使用 Discord 机器人在多个渠道中嵌入消息?

我在其他用户的问题中查找,找到了我正在寻找的内容。我的问题是,我希望同一个机器人在不同的频道上使用不同的标题、页脚等执行相同的工作......


主要代码是:


const Discord = require("discord.js");


const client = new Discord.Client();


const channel = client.channels.cache.get("channel id");


client.on("ready", async () => {

    console.log(`Bot has started`);


    client.user.setPresence({ activity: { name: "some status " }, status: "online" });

});

client.on("message", (message) => {

    if (message.author.bot) 

    return;

    const embed = new MessageEmbed()

    .setDescription(message.content)

    .setTitle("")

    .setAuthor(message.author.tag,message.author.displayAvatarURL())

    .setImage(message.attachments.first().url)

    .setFooter("", "")

    .setTimestamp();

    channel.send(embed).catch(console.error);

});


client.login("token");


小唯快跑啊
浏览 58回答 1
1回答

大话西游666

首先,您可以在对象中声明消息,然后使用它们发送到不同的渠道。    //Here goes the dynamic setting for different channels    const messages = {      'IdChannel':{        embed:{          title:'foo',          description: message.content,          footer: {text:'foo'}        }      },      'scndChannelID':{        embed:{          title:'bar',          description: message.content,          footer: {text:'bar'}        }      }    }然后在事件消息上使用它发送到您需要在对象键上声明的通道      Object.keys(messagex).forEach((value,index) => {        //Here can go the static things        message.guild.channels.cache.get(value).send(          {embed:{...messagex[value].embed,          timestamp: new Date(),          image: {url:""}          }})      })
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript