mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 16:24:25 -05:00
Merge pull request #266 from fantinodavide/master
Prevent crash when a discord channel cannot be fetched by channelID
This commit is contained in:
commit
bc4095eb8c
@ -15,10 +15,21 @@ export default class DiscordBasePlugin extends BasePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async prepareToMount() {
|
async prepareToMount() {
|
||||||
|
try {
|
||||||
this.channel = await this.options.discordClient.channels.fetch(this.options.channelID);
|
this.channel = await this.options.discordClient.channels.fetch(this.options.channelID);
|
||||||
|
} catch (error) {
|
||||||
|
this.channel = null;
|
||||||
|
this.verbose(1, `Could not fetch Discord channel with channelID "${this.options.channelID}". Error: ${error.message}`);
|
||||||
|
this.verbose(2, `${error.stack}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendDiscordMessage(message) {
|
async sendDiscordMessage(message) {
|
||||||
|
if (!this.channel) {
|
||||||
|
this.verbose(1, `Could not send Discord Message. Channel not initialized.`)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof message === 'object' && 'embed' in message)
|
if (typeof message === 'object' && 'embed' in message)
|
||||||
message.embed.footer = message.embed.footer || { text: COPYRIGHT_MESSAGE };
|
message.embed.footer = message.embed.footer || { text: COPYRIGHT_MESSAGE };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user