【问题标题】:Discord.js delete all bot and user message when triggerDiscord.js 触发时删除所有机器人和用户消息
【发布时间】:2021-08-19 20:28:49
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    如果我理解正确,您想删除来自用户和机器人的所有消息,这将是命令、响应、您等待的额外信息,而不是响应?好吧,你去吧,这很快就出现在我的脑海中,可能有更好的方法:

    //...
    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-08-06
      • 2018-04-29
      • 2020-10-26
      • 2020-11-02
      • 2021-07-27
      • 1970-01-01
      • 2020-11-26
      • 1970-01-01
      • 2021-03-06
      相关资源
      最近更新 更多