【问题标题】:Deleting a message after it was copied and send to another Channel在复制并发送到另一个频道后删除消息
【发布时间】:2021-08-26 01:07:13
【问题描述】:

我想弄清楚如何在将消息复制并发送到另一个频道后删除它

我的代码是:

bot.on("message", async (message) => {
  if (message.content.startsWith("t!logout")) {
    var str = message.content.slice(" ");
    bot.channels.cache
      .get("8786607442820137469")
      .send(
        `New Message from: ${message.author.username}#${message.author.discriminator} ` +
          str
      );
  }
});

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

    我相信这是您正在寻找的代码:

    bot.on("messageCreate", async (message) => {
        if (message.content.startsWith("t!logout")) {
            var str = message.content.slice(" ");
    
            // Replace this with the channel ID 
            const channelToSendId = "CHANNEL_ID";
    
            // Wait for the bot to send the message
            await bot.channels.cache
                .get(channelToSendId)
                .send(
                    `New Message from: ${message.author.username}#${message.author.discriminator} ` +
                        str
                );
    
            // Delete the message
            message.delete();
        }
    });
    

    如果你想发送嵌入,你可以做类似的事情

    bot.on("messageCreate", async (message) => {
        if (message.content.startsWith("t!logout")) {
            var str = message.content.slice(" ");
    
            // Replace this with the channel ID 
            const channelToSendId = "CHANNEL_ID";
          
           const embed = new Discord.MessageEmbed()
           .setAuthor(`New Message from: ${message.author.username}#${message.author.discriminator}`)
           .setDescription(`Content: ${str}`)
    
            // Wait for the bot to send the message
            await bot.channels.cache
                .get(channelToSendId)
                .send(embed);
    
            // Delete the message
            message.delete();
        }
    });
    
    

    【讨论】:

    • 我试过你的代码,它正在工作,但我还有另一个问题。我想发送嵌入消息而不是普通消息,但我不知道我应该如何使用该代码来做到这一点。你能帮我解决这个问题吗?
    • 完成@IneedHelp
    • 嘿,我还有一个问题。我想在不同的服务器上使用机器人,显然我用来在另一个通道中发送消息的通道 ID 在另一个服务器上不起作用。有没有机会解决这个问题?
    猜你喜欢
    • 1970-01-01
    • 2021-02-06
    • 2018-11-24
    • 2021-12-31
    • 2020-08-29
    • 2022-01-09
    • 2019-10-23
    • 2019-03-05
    • 1970-01-01
    相关资源
    最近更新 更多