【问题标题】:How to fetch a embed and have it posted in another channel如何获取嵌入并将其发布到另一个频道
【发布时间】:2020-07-21 03:59:35
【问题描述】:

我正在尝试为我的 Discord Bot 创建报告功能。当前,如果用户输入 %report(用户名)(规则#已损坏)(详细信息)。该机器人在员工聊天中创建一个待处理的报告作为嵌入。我希望工作人员能够使用命令通过其 ID 获取嵌入,并将其发送到另一个不和谐频道以供进一步审查。目前我想不出任何想法来实现这个结果,我想知道这里是否有人能指出我正确的方向。

我打算让命令像这样工作,%review (message ID)。 这将获取当前在员工聊天中的消息,并将其发送给更高的权威机构以供进一步审查。

P.S 我的代码组织得不好,对此我深表歉意。我将尝试回答您可能遇到的任何问题,以便我消除困惑。

 bot.on("message", async message => {

if(message.author.bot) return;

if(!message.content.startsWith(config.prefix)) return;

const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();

if(command === 'report'){
        console.log((message.author.username)+ ' is trying to create a report');
            let username = args[0]
            let rule = args[1]
            let notes = args.splice(2).join(" ")
            const report = new discord.MessageEmbed()
            .setColor('#0099ff')
            .setTitle("Pending Report")
            .setFooter("UMA Report")
            .addField('username: ', username)
            .addField('Rule Broken: ', rule)
            .addField('Notes: ', notes)
            .addField('Report Set By: ', "<@" + message.author.id + ">")
            .setTimestamp()
            bot.channels.cache.get('53453453345').send({ embed: report })
            console.log((message.author.username)+ ' has created a report on: '+ username);
            
        
    }

}

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    这应该从员工频道获取消息并将其重新发送到另一个频道。

    } else if (command === 'review') {
      let ID = args[0];
      const embedMessage = await message.channel.messages.fetch(ID);
      const embed = embedMessage.embeds[0];
      (await bot.channels.fetch(/* other channel ID */)).send(embedMessage.content, { embed });
    }
    

    参考资料:

    【讨论】:

    • 您好,感谢您的回复。您的解决方案设法检索了正常工作的常规消息。不幸的是,每当机器人试图获取嵌入时,它都会返回一个控制台错误,指出消息内容为空。我从中了解到的是嵌入不是在代码中获取的。但是,我仍然要感谢您,因为这为我指明了该项目的正确方向。
    • @TheTecno 我已经修改了代码,希望它可以与嵌入一起使用。手指交叉?。
    • 非常感谢!编辑就像一个魅力。嵌入具有提供给它并发送到指定通道的所有数据。再次感谢,我一直在尝试解决这个问题。
    猜你喜欢
    • 2018-11-24
    • 2022-07-01
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    • 2019-10-23
    • 1970-01-01
    相关资源
    最近更新 更多