Discord.js 触发时删除所有机器人和用户消息
Discord.js delete all bot and user message when trigger
正如我在标题中所说,我希望机器人删除激活命令后使用的所有消息,结果只留下嵌入,但我不能'不要这样做。有什么线索吗?
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 发出命令
如果我没理解错的话,你想删除所有来自用户和机器人的消息,这将是命令、响应、你等待的额外信息,而不是那个响应?好了,开始吧,我很快就想到了这个,可能有更好的方法:
//...
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())
正如我在标题中所说,我希望机器人删除激活命令后使用的所有消息,结果只留下嵌入,但我不能'不要这样做。有什么线索吗?
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 发出命令
如果我没理解错的话,你想删除所有来自用户和机器人的消息,这将是命令、响应、你等待的额外信息,而不是那个响应?好了,开始吧,我很快就想到了这个,可能有更好的方法:
//...
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())