Implement error handling for rolemenu
This commit is contained in:
parent
3c01d37bd5
commit
e075a3a5d6
@ -54,7 +54,12 @@
|
|||||||
"invalidSubcommand": "Invalid subcommand detected.",
|
"invalidSubcommand": "Invalid subcommand detected.",
|
||||||
"noTreeMessage": "</tree:0> - Make sure you've sent or refreshed a Tree recently.",
|
"noTreeMessage": "</tree:0> - Make sure you've sent or refreshed a Tree recently.",
|
||||||
"noLeaderboardMessage": "</top trees:0> - Make sure you've sent or refreshed the Tallest Trees leaderboard recently.",
|
"noLeaderboardMessage": "</top trees:0> - Make sure you've sent or refreshed the Tallest Trees leaderboard recently.",
|
||||||
"noCompareMessage": "</compare:0> - This is awkward, I've lost my own comparison message!"
|
"noCompareMessage": "</compare:0> - This is awkward, I've lost my own comparison message!",
|
||||||
|
"noFetchRole": "I was unable to find that role, please make sure it exists and I have access to it.",
|
||||||
|
"noGiveRole": "I was unable to give that role to you, please make sure I have permission to `Manage Roles` and that the role is below my role in the server settings role list.",
|
||||||
|
"noTakeRole": "I was unable to remove that role from you, please make sure I have permission to `Manage Roles` and that the role is below my role in the server settings role list.",
|
||||||
|
"yesGiveRole": "Successfully added the role to your profile!",
|
||||||
|
"yesTakeRole": "Successfully removed the role from your profile!"
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
"treeAndLeaderboard": "Tree and leaderboard messages were both found, setup is complete. Run </setupinfo:1065413032374706196> to verify. Run </compare:1065346941166297128> to get started!",
|
"treeAndLeaderboard": "Tree and leaderboard messages were both found, setup is complete. Run </setupinfo:1065413032374706196> to verify. Run </compare:1065346941166297128> to get started!",
|
||||||
|
10
main.js
10
main.js
@ -89,7 +89,15 @@ client.on('interactionCreate', async interaction => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on('messageUpdate', async (oldMessage, message) => {
|
client.on('messageUpdate', async (oldMessage, message) => {
|
||||||
await fn.messages.updateHandler(message).catch(e => console.error(e));
|
await fn.messages.updateHandler(message).catch(async e => {
|
||||||
|
switch (e) {
|
||||||
|
case strings.error.noCompareMessage:
|
||||||
|
await message.channel.send(strings.error.noCompareMessage);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('messageCreate', async message => {
|
client.on('messageCreate', async message => {
|
||||||
|
@ -751,18 +751,24 @@ const functions = {
|
|||||||
async fruitPing(interaction) {
|
async fruitPing(interaction) {
|
||||||
if (interaction.client.guildInfos.has(interaction.guildId)) {
|
if (interaction.client.guildInfos.has(interaction.guildId)) {
|
||||||
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
|
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
|
||||||
const role = await functions.roles.fetchRole(interaction.guild, guildInfo.fruitRoleId);
|
|
||||||
let status = "No Changes Made";
|
let status = "No Changes Made";
|
||||||
|
let errorFlag = false;
|
||||||
|
const role = await functions.roles.fetchRole(interaction.guild, guildInfo.fruitRoleId).catch(e => {
|
||||||
|
errorFlag = true;
|
||||||
|
status = strings.error.noFetchRole;
|
||||||
|
});
|
||||||
if (interaction.member.roles.cache.some(role => role.id == guildInfo.fruitRoleId)) {
|
if (interaction.member.roles.cache.some(role => role.id == guildInfo.fruitRoleId)) {
|
||||||
await functions.roles.takeRole(interaction.member, role);
|
await functions.roles.takeRole(interaction.member, role).catch(e => {
|
||||||
status = "Removed the fruit role.";
|
errorFlag = true;
|
||||||
|
status = strings.error.noTakeRole;
|
||||||
|
});
|
||||||
|
if(!errorFlag) status = strings.error.yesTakeRole;
|
||||||
} else {
|
} else {
|
||||||
await functions.roles.giveRole(interaction.member, role).catch(e => {
|
await functions.roles.giveRole(interaction.member, role).catch(e => {
|
||||||
const errorId = functions.generateErrorId();
|
errorFlag = true;
|
||||||
console.error(errorId + " " + e);
|
status = strings.error.noGiveRole;
|
||||||
status = `Error adding the fruit role: ${errorId}`;
|
|
||||||
});
|
});
|
||||||
status = "Added the fruit role.";
|
if (!errorFlag) status = strings.error.yesGiveRole;
|
||||||
}
|
}
|
||||||
return functions.builders.embed(status);
|
return functions.builders.embed(status);
|
||||||
} else {
|
} else {
|
||||||
@ -773,13 +779,23 @@ const functions = {
|
|||||||
if (interaction.client.guildInfos.has(interaction.guildId)) {
|
if (interaction.client.guildInfos.has(interaction.guildId)) {
|
||||||
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
|
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
|
||||||
let status = "No Changes Made";
|
let status = "No Changes Made";
|
||||||
const role = await functions.roles.fetchRole(interaction.guild, guildInfo.waterRoleId);
|
let errorFlag = false;
|
||||||
|
const role = await functions.roles.fetchRole(interaction.guild, guildInfo.waterRoleId).catch(e => {
|
||||||
|
errorFlag = true;
|
||||||
|
status = strings.error.noFetchRole;
|
||||||
|
});
|
||||||
if (interaction.member.roles.cache.some(role => role.id == guildInfo.waterRoleId)) {
|
if (interaction.member.roles.cache.some(role => role.id == guildInfo.waterRoleId)) {
|
||||||
await functions.roles.takeRole(interaction.member, role);
|
await functions.roles.takeRole(interaction.member, role).catch(e => {
|
||||||
status = "Removed the water role.";
|
errorFlag = true;
|
||||||
|
status = strings.error.noTakeRole;
|
||||||
|
});
|
||||||
|
if (!errorFlag) status = strings.error.yesTakeRole;
|
||||||
} else {
|
} else {
|
||||||
await functions.roles.giveRole(interaction.member, role);
|
await functions.roles.giveRole(interaction.member, role).catch(e => {
|
||||||
status = "Added the water role.";
|
errorFlag = true;
|
||||||
|
status = strings.error.noGiveRole;
|
||||||
|
});
|
||||||
|
if (!errorFlag) status = strings.error.yesGiveRole;
|
||||||
}
|
}
|
||||||
return functions.builders.embed(status);
|
return functions.builders.embed(status);
|
||||||
} else {
|
} else {
|
||||||
@ -789,13 +805,13 @@ const functions = {
|
|||||||
},
|
},
|
||||||
roles: {
|
roles: {
|
||||||
async fetchRole(guild, roleId) {
|
async fetchRole(guild, roleId) {
|
||||||
return await guild.roles.fetch(roleId).catch(err => console.error("Error fetching the role: " + err + "\n" + roleId));
|
return await guild.roles.fetch(roleId);
|
||||||
},
|
},
|
||||||
async giveRole(member, role) {
|
async giveRole(member, role) {
|
||||||
await member.roles.add(role).catch(err => console.error(`Error giving role: ${err}\nRole Info: ${role.name} (${role.guild}: ${member.guild.name})`));
|
await member.roles.add(role);
|
||||||
},
|
},
|
||||||
async takeRole(member, role) {
|
async takeRole(member, role) {
|
||||||
await member.roles.remove(role).catch(err => console.error(`Error removing role: ${err}\nRole Info: ${role.name} (${role.guild}: ${member.guild.name})`));
|
await member.roles.remove(role);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
collectors: {
|
collectors: {
|
||||||
|
Loading…
Reference in New Issue
Block a user