Skip to content

Commit 65932bb

Browse files
committed
Skip channels without permission
1 parent 101d93f commit 65932bb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/utils/Utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@ export async function sendToChannels(channels: {channelID: Snowflake, pingRole?:
2020
for (const channel of channels) {
2121
try {
2222
const chanObj = await client.channels.fetch(channel.channelID)
23-
if (!(chanObj && chanObj.isTextBased()))
23+
if (!(chanObj && chanObj.isTextBased())) {
24+
Logger.error(`Invalid channel ${channel.channelID}`)
2425
continue
26+
}
27+
28+
if (chanObj instanceof GuildChannel)
29+
if (!(chanObj.permissionsFor(client.user!)?.has("SendMessages") && chanObj.permissionsFor(client.user!)?.has("ViewChannel"))) {
30+
Logger.error(`Missing permissions in ${chanObj.id} (${chanObj.name})`)
31+
continue
32+
}
33+
2534
if (embed && ((content && content.length > 0) || (channel.pingRole && channel.pingRole.length > 0)))
2635
messages.push(chanObj.send({
2736
content: `${channel.pingRole && channel.pingRole != "" ? `<@&${channel.pingRole}> ` : ""}${content ?? ""}`.trim(),

0 commit comments

Comments
 (0)