0

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

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 来发出命令

4

1 回答 1

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())
于 2021-06-02T03:06:08.007 回答