diff --git a/index.js b/index.js index 09868a5..e60921d 100644 --- a/index.js +++ b/index.js @@ -832,21 +832,26 @@ discord.on("interactionCreate", async (interaction) => { filterEvt = interaction.options.getString("filterevt") || null; message = interaction.options.getString("message") || null; if (interaction.inGuild()) { - db.get(`SELECT * FROM channels WHERE channelid = ? AND iemchannel = ?`, [interaction.channel.id, room], (err, row) => { - if (err) { - console.error(err.message); - interaction.reply({ content: "Failed to subscribe to room", ephemeral: true }); - } else if (row) { - return interaction.reply({ content: `Already subscribed to \`${getWFOByRoom(room).location}\`\nIf you want to update a subscribtion, please unsubscribe and resubscribe. This will be made a command eventually.`, ephemeral: true }); - } - db.run(`INSERT INTO channels (channelid, iemchannel, custommessage, filter, filterEvt, minPriority) VALUES (?, ?, ?, ? ,? ,?)`, [interaction.channel.id, room, message, filter, filterEvt, minPriority], (err) => { + interaction.channel.send("Permission check").then((msg) => { + msg.delete(); + db.get(`SELECT * FROM channels WHERE channelid = ? AND iemchannel = ?`, [interaction.channel.id, room], (err, row) => { if (err) { console.error(err.message); interaction.reply({ content: "Failed to subscribe to room", ephemeral: true }); - } else { - interaction.reply({ content: `Subscribed to \`${getWFOByRoom(room).location}\``, ephemeral: true }); + } else if (row) { + return interaction.reply({ content: `Already subscribed to \`${getWFOByRoom(room).location}\`\nIf you want to update a subscribtion, please unsubscribe and resubscribe. This will be made a command eventually.`, ephemeral: true }); } + db.run(`INSERT INTO channels (channelid, iemchannel, custommessage, filter, filterEvt, minPriority) VALUES (?, ?, ?, ? ,? ,?)`, [interaction.channel.id, room, message, filter, filterEvt, minPriority], (err) => { + if (err) { + console.error(err.message); + interaction.reply({ content: "Failed to subscribe to room", ephemeral: true }); + } else { + interaction.reply({ content: `Subscribed to \`${getWFOByRoom(room).location}\``, ephemeral: true }); + } + }); }); + }).catch((err) => { + interaction.reply({ content: "Failed to subscribe to room. Bot does not have send message permissions here!", ephemeral: true }); }); } else { // We're in a DM db.get(`SELECT * FROM userAlerts WHERE userid = ? AND iemchannel = ?`, [interaction.user.id, room], (err, row) => {