forked from ChrisChrome/weather-bot
Possibly notify of bad perms?
This commit is contained in:
parent
d653bc3e90
commit
8b94e7e3f8
17
index.js
17
index.js
|
@ -36,10 +36,6 @@ const rest = new REST({
|
|||
version: '10'
|
||||
}).setToken(config.discord.token);
|
||||
|
||||
discord.on("error", (err) => {
|
||||
console.log(`${colors.red("[ERROR]")} Discord error: ${err}`);
|
||||
})
|
||||
|
||||
// Setup SQlite DB
|
||||
const db = new sqlite3.Database("channels.db", (err) => {
|
||||
if (err) {
|
||||
|
@ -451,7 +447,7 @@ xmpp.on("stanza", (stanza) => {
|
|||
console.log(`${colors.red("[ERROR]")} ${err.message}`);
|
||||
}
|
||||
if (!rows) return; // No channels to alert
|
||||
rows.forEach((row) => {
|
||||
rows.forEach(async (row) => {
|
||||
// Get Filters as arrays
|
||||
if (!row.filterEvt) row.filterEvt = "";
|
||||
if (!row.filter) row.filter = "";
|
||||
|
@ -464,7 +460,14 @@ xmpp.on("stanza", (stanza) => {
|
|||
|
||||
let channel = discord.channels.cache.get(row.channelid);
|
||||
if (!channel) return console.log(`${colors.red("[ERROR]")} Channel ${row.channelid} not found`);
|
||||
|
||||
if (!channel.permissionsFor(discord.user).has("SEND_MESSAGES")) {
|
||||
const logs = await channel.guild.fetchAuditLogs({ type: Discord.AuditLogEvent.BotAdd });
|
||||
const user = logs.entries.find(entry => entry.target.id === discord.user.id)?.executor;
|
||||
if (user) {
|
||||
user.send(`I don't have permission to send messages in the channel ${channel.name} (${channel.id}) in the guild ${channel.guild.name} (${channel.guild.id}). Please update my permissions.`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// fetch the product text
|
||||
trySend = () => {
|
||||
fetch(`https://mesonet.agron.iastate.edu/api/1/nwstext/${product_id_raw}`).then((res) => {
|
||||
|
@ -478,7 +481,7 @@ xmpp.on("stanza", (stanza) => {
|
|||
}).then((msg) => {
|
||||
if (msg.channel.type === Discord.ChannelType.GuildAnnouncement) msg.crosspost();
|
||||
}).catch((err) => {
|
||||
console.log(`${colors.yellow("[WARN]")} Failed to send message to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id}): ${err}`);
|
||||
console.log(`${colors.yellow("[WARN]")} Failed to send message to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id})`);
|
||||
});
|
||||
});
|
||||
}).catch((err) => {
|
||||
|
|
Loading…
Reference in a new issue