亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 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 關注
  • 159 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號