Only delete messages if they exist, removes errors in console

This commit is contained in:
TheEssem 2020-09-23 14:12:39 -05:00
parent 7047081f98
commit 6e8473d784
9 changed files with 14 additions and 14 deletions

View file

@ -13,7 +13,7 @@ exports.run = async (message, args) => {
type: image.type.toUpperCase(),
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
});
await processMessage.delete();
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
return {
file: outputFinal,
name: `caption.${image.type}`

View file

@ -13,7 +13,7 @@ exports.run = async (message, args) => {
type: image.type.toUpperCase(),
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
});
await processMessage.delete();
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
return {
file: outputFinal,
name: `caption2.${image.type}`

View file

@ -10,7 +10,7 @@ exports.run = async (message) => {
type: image.type.toUpperCase(),
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
});
await processMessage.delete();
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
return {
file: buffer,
name: "globe.gif"

View file

@ -10,7 +10,7 @@ exports.run = async (message) => {
type: image.type.toUpperCase(),
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
});
await processMessage.delete();
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
return {
file: buffer,
name: `magik.${image.type}`

View file

@ -15,7 +15,7 @@ exports.run = async (message, args) => {
type: image.type.toUpperCase(),
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
});
processMessage.delete();
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
return {
file: buffer,
name: `motivate.${image.type}`

View file

@ -10,7 +10,7 @@ exports.run = async (message) => {
type: image.type.toUpperCase(),
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
});
await processMessage.delete();
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
return {
file: buffer,
name: "spin.gif"

View file

@ -14,7 +14,7 @@ module.exports = async (member, oldChannel) => {
soundPlayer.players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: member.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel });
waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`);
} else {
waitMessage.delete();
if (waitMessage.channel.messages.get(waitMessage.id)) waitMessage.delete();
connection.player.stop(connection.originalChannel.guild.id);
soundPlayer.manager.leave(connection.originalChannel.guild.id);
connection.player.destroy();
@ -28,11 +28,11 @@ module.exports = async (member, oldChannel) => {
const awaitRejoin = new AwaitRejoin(oldChannel, false, member.id);
awaitRejoin.on("end", (rejoined) => {
if (rejoined) {
waitMessage.delete();
if (waitMessage.channel.messages.get(waitMessage.id)) waitMessage.delete();
} else {
const members = oldChannel.voiceMembers.filter((i) => i.id !== client.user.id);
if (members.length === 0) {
waitMessage.delete();
if (waitMessage.channel.messages.get(waitMessage.id)) waitMessage.delete();
connection.player.stop(connection.originalChannel.guild.id);
soundPlayer.manager.leave(connection.originalChannel.guild.id);
connection.player.destroy();

View file

@ -27,7 +27,7 @@ module.exports = async (message, pages, timeout = 120000) => {
maxMatches: 1
});
return messageCollector.on("message", response => {
askMessage.delete();
if (askMessage.channel.messages.get(askMessage.id)) askMessage.delete();
page = Number(response.content) - 1;
currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("🔢", userID);
@ -44,7 +44,7 @@ module.exports = async (message, pages, timeout = 120000) => {
case "🗑":
deleted = true;
reactionCollector.emit("end");
currentPage.delete();
if (currentPage.channel.messages.get(currentPage.id)) currentPage.delete();
return;
default:
break;

View file

@ -103,7 +103,7 @@ exports.nextSong = async (message, connection, track, info, music, voiceChannel,
this.players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: message.author.id, voiceChannel: voiceChannel, originalChannel: message.channel });
if (inQueue) {
connection.on("error", (error) => {
playingMessage.delete();
if (playingMessage.channel.messages.get(playingMessage.id)) playingMessage.delete();
this.manager.leave(voiceChannel.guild.id);
connection.destroy();
this.players.delete(voiceChannel.guild.id);
@ -122,11 +122,11 @@ exports.nextSong = async (message, connection, track, info, music, voiceChannel,
this.players.delete(voiceChannel.guild.id);
this.queues.delete(voiceChannel.guild.id);
if (music) await client.createMessage(message.channel.id, "🔊 The current voice channel session has ended.");
await playingMessage.delete();
if (playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete();
} else {
const track = await fetch(`http://${connection.node.host}:${connection.node.port}/decodetrack?track=${encodeURIComponent(newQueue[0])}`, { headers: { Authorization: connection.node.password } }).then(res => res.json());
this.nextSong(message, connection, newQueue[0], track, music, voiceChannel, true);
await playingMessage.delete();
if (playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete();
}
});
};