Skip to content

Commit

Permalink
"added some extra checks"
Browse files Browse the repository at this point in the history
  • Loading branch information
Josee9988 committed Jun 26, 2021
1 parent 58e5d19 commit a38fbc4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/commands/commands-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ export default class CommandsController {
let dimgs = await this.databaseController.findAll();
// iterate over every document and send the photos to every respective server
for (const dimg of dimgs) {
if (dimg.albumLink != null || dimg.channelId != null)
await this.fetchAndSendPhoto(dimg).catch(() => console.error(`fetchAndSendPhoto failed for server ${dimg.serverId}`));
if (dimg != null && dimg.albumLink != null && dimg.channelId != null && dimg.serverId != null) {
this.fetchAndSendPhoto(dimg).catch(() => console.error(`fetchAndSendPhoto failed for server ${dimg.serverId}`));
}
}
}
}
Expand All @@ -174,7 +175,7 @@ export default class CommandsController {

if (dimg.channelId && this.client.channels.cache.get(dimg.channelId)) { // if the channel is specified send the image
if (!photos[randomPhoto] || !photos[randomPhoto].url) {
console.error("Url does not exist for server " + dimg.serverId + " with the photo object being like: " + photos[randomPhoto] + "object:");
console.error("Url does not exist for server " + dimg.serverId + " with the photo object being like: " + photos[randomPhoto] + " object:");
return;
}
await this.client.channels.cache.get(dimg.channelId).send(photos[randomPhoto].url)
Expand Down

0 comments on commit a38fbc4

Please sign in to comment.