为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

小唯快跑啊 2023-11-11 21:23:40
我在其他用户的问题中查找,找到了我正在寻找的内容。我的问题是,我希望同一个机器人在不同的频道上使用不同的标题、页脚等执行相同的工作......主要代码是: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");
查看完整描述

1 回答

?
大话西游666

TA贡献1817条经验 获得超14个赞

首先,您可以在对象中声明消息,然后使用它们发送到不同的渠道。


    //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:""}

          }})

      })


查看完整回答
反对 回复 2023-11-11
  • 1 回答
  • 0 关注
  • 55 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信