Situation
I have created a simple Discord bot which uses message embeds to run a text style adventure quest. Upon calling the bot in a channel it logs the iD of the user that calls it and ensures only that user can interact with the buttons, throwing up an error when another user tries to interact. I have been testing the bot on my personal server (and other new servers) and it has been working fine with no issues around storing the user id and checking that on each interaction.
The bot requires the following permissions only: View Messages / View Channels
Manage messages
Embed Links
Send Messages
Complication
Now that the bot and quest have been completed I have added it to the server we intend to run it on (using the same permissions link) and it throws up a permission error as follows when the user starts the bot and clicks the play button: (https://i.ibb.co/pWN0Hw1/unknown.png) This suggests that it hasn't stored the user iD of the user who started the command correctly despite it working fine on other servers (I.e. the user can continue the quest without the error coming back).
An extract of the full code which covers the storing of the iD and checks it against the interaction is here:
const { Client, Intents, MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'),
client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES ] });
client.db = require("quick.db");
var config = {
token: "Removed",
prefix: "/",
adminID: "admin id",
embed_color: "#ffffff"
};
var quiz = require("./quiz.json");
client.login(config.token);
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
if ([null, undefined].includes(client.db.get(`quiz`))) client.db.set(`quiz`, {});
if ([null, undefined].includes(client.db.get(`quiz.spawns`))) client.db.set(`quiz.spawns`, {});
});
client.on('messageCreate', async (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "unlock") {
message.delete();
const m = await message.channel.send(getMMenuPage());
client.db.set(`quiz.spawns.m${m.id}`, message.author.id);
}
});
client.on('interactionCreate', async (interaction) => {
if (interaction.isButton()) {
if (client.db.get(`quiz.spawns.m${interaction.message.id}`) != interaction.user.id) return interaction.reply(getMessagePermissionError(client.db.get(`quiz.spawns.m${interaction.message.id}`)));
const q = quiz;
And here's the error handler:
}
function getMessagePermissionError(ownerId) {
return {
embeds: [
new MessageEmbed()
.setTitle(`Permission Error`)
.setDescription(`This game was started by another user: <@${ownerId}>\nIf you want to play by yourself, use the command **/unlock**`)
],
ephemeral: true
};
}
Is there any reason why this would work on some servers but not one in particular, when applying the exact same permissions?
Thanks for your help.