Discord.js 触发时删除所有机器人和用户消息

时间:2021-06-01 15:59:37

标签: node.js discord discord.js bots commando

正如我在标题中所说的,我希望机器人在激活命令后删除所有使用的消息,结果只留下嵌入,但我不能这样做。有什么线索可以这样做吗?

const { Command } = require("discord.js-commando");
const Discord = require("discord.js");

module.exports = class PruebaCommand extends Command {
  constructor(client) {
    super(client, {
      name: "prueba",
      aliases: ["test"],
      group: "general",
      memberName: "prueba",
      guildOnly: true,
      description: " -  ",
    });
  }

  run(message, args) {
    let embed1 = new Discord.MessageEmbed();
    const filter = (m) => m.author.id == message.author.id;
    message.channel.send(
      `Proporciona el nombre del jugador al cual te gustaría añadir a la DODGE LIST`
    );
    message.channel
      .awaitMessages(filter, { time: 30000, max: 1 })
      .then((msg) => {
        let msg1 = msg.first().content;
        message.channel.send(`Link de tu Imagen`).then((msg) => {
          msg.channel
            .awaitMessages(filter, { time: 30000, max: 1 })
            .then((msg) => {
              let msg2 = msg.first().content;

              message.channel.send(`Correcto, creando tu embed`).then((msg) => {
                embed1.setAuthor("˜”*°•.˜”*°• DODGE LIST •°*”˜.•°*”˜");
                embed1.setDescription(
                  "Un nuevo jugador ha sido añadido a la Dodge List"
                );
                embed1.addFields(
                  { name: "__NOMBRE:__", value: msg1 },
                  { name: "__SERVIDOR:__", value: "LAS" }
                );
                embed1.setImage(msg2);
                embed1.setColor("RANDOM");
                message.channel.send(embed1);
              });
            });
        });
      });
  }
};

抱歉,如果代码有点奇怪,或者以不应该的方式执行,我是新手,从未使用过 awaitMessages 来创建命令

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您想删除来自用户和机器人的所有消息,即命令、响应、您等待的额外信息,而不是那个响应?好吧,你开始吧,我很快想到了这个,可能有更好的方法:

//...
var messages = [message];
//...
<channel>.awaitMessages(filter, options)
.then(msgs => messages.push(msgs.first())) //keep in mind this would only work if it’s 1 message max
//... at the end of all the awaitMessages, put this:
messages.forEach(m => m.delete())