check if message exists
This commit is contained in:
parent
403cefc737
commit
fc427fd008
1 changed files with 41 additions and 29 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { GuildBasedChannel, Message } from 'discord.js';
|
import { Message, TextBasedChannel } from 'discord.js';
|
||||||
|
|
||||||
/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-messageCreate */
|
/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-messageCreate */
|
||||||
export default (message: Message) => {
|
export default async (message: Message) => {
|
||||||
// Ignore message if
|
// Ignore message if
|
||||||
if (
|
if (
|
||||||
// Author is a bot
|
// Author is a bot
|
||||||
|
@ -28,10 +28,11 @@ export default (message: Message) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const messages = (
|
const messages = (
|
||||||
|
await Promise.all(
|
||||||
urls.reduce(
|
urls.reduce(
|
||||||
(data: {
|
(data: {
|
||||||
message_id: string;
|
message_id: string;
|
||||||
found_channel: GuildBasedChannel;
|
channel: TextBasedChannel;
|
||||||
}[] = [], match) => {
|
}[] = [], match) => {
|
||||||
const [,
|
const [,
|
||||||
guild_id,
|
guild_id,
|
||||||
|
@ -44,21 +45,32 @@ export default (message: Message) => {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const found_channel =
|
const channel =
|
||||||
message.guild.channels.cache.get(channel_id);
|
message.guild.channels.cache.get(channel_id) as TextBasedChannel;
|
||||||
|
|
||||||
// If channel doesn't exist in the guild
|
// If channel doesn't exist in the guild and isn't text
|
||||||
if (!found_channel) {
|
if (!channel) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.push({ message_id, found_channel });
|
data.push({ message_id, channel });
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
},
|
}, []
|
||||||
[]
|
).map(async ({ message_id, channel }) => {
|
||||||
)
|
const quoted_message = await channel.messages
|
||||||
);
|
.fetch(message_id)
|
||||||
|
.catch(() => undefined);
|
||||||
|
|
||||||
|
// If message doesn't exist or empty
|
||||||
|
if (!quoted_message || (!quoted_message.content && quoted_message.attachments.size == 0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return quoted_message;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
// Remove undefined elements
|
||||||
|
).filter(Boolean);
|
||||||
|
|
||||||
console.log(messages);
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue