Arcane_ish
Arcane_ish
DIAdiscord.js - Imagine an app
Created by Arcane_ish on 6/23/2023 in #djs-questions
Can't read default_member_permissions from SlashCommandBuilder?
facepalms thanks!
9 replies
DIAdiscord.js - Imagine an app
Created by Arcane_ish on 6/23/2023 in #djs-questions
Can't read default_member_permissions from SlashCommandBuilder?
Notably, I have it hardcoded to .setDefaultMemberPermissions(PermissionFlagsBits.ViewChannel) to reduce complexity for debugging, but normally it's just putting defaultMemberPermission straight in there without any modifications.
9 replies
DIAdiscord.js - Imagine an app
Created by Arcane_ish on 6/23/2023 in #djs-questions
Can't read default_member_permissions from SlashCommandBuilder?
Seems plausible to me, but I'm stumped on what's going wrong specifically. Here's the CommandWrapper in its entirety:
class CommandWrapper extends module.exports.InteractionWrapper {
/** Additional wrapper properties for command parsing
* @param {string} customIdInput
* @param {string} descriptionInput
* @param {import("discord.js").PermissionFlags} defaultMemberPermission
* @param {boolean} isPremiumCommand
* @param {boolean} allowInDMsInput
* @param {number} cooldownInMS
* @param {{type: "Attachment" | "Boolean" | "Channel" | "Integer" | "Mentionable" | "Number" | "Role" | "String" | "User", name: string, description: string, required: boolean, choices: { name: string, value }[]}[]} optionsInput
* @param {{name: string, description: string, optionsInput: {type: "Attachment" | "Boolean" | "Channel" | "Integer" | "Mentionable" | "Number" | "Role" | "String" | "User", name: string, description: string, required: boolean, choices: { name: string, value }[]}}[]} subcommandsInput
* @param {(interaction: import("discord.js").Interaction) => void} executeFunction
*/
constructor(customIdInput, descriptionInput, defaultMemberPermission, isPremiumCommand, allowInDMsInput, cooldownInMS, optionsInput, subcommandsInput, executeFunction) {
super(customIdInput, cooldownInMS, executeFunction);
this.description = descriptionInput;
this.premiumCommand = isPremiumCommand;
this.data = new SlashCommandBuilder()
.setName(customIdInput)
.setDescription(descriptionInput)
.setDefaultMemberPermissions(PermissionFlagsBits.ViewChannel)
.setDMPermission(allowInDMsInput);
console.log("inside wrapper", this.data);
optionsInput.forEach(option => {
this.data[`add${option.type}Option`](built => {
built.setName(option.name).setDescription(option.description).setRequired(option.required);
if (option.choices === null || option.choices === undefined) {
throw new Error(`${this.customId} (${descriptionInput}) ${option.type} Option was nullish.`);
}
if (option.choices.length) {
built.addChoices(...option.choices);
}
return built;
})
})
subcommandsInput.forEach(subcommand => {
this.data.addSubcommand(built => {
built.setName(subcommand.name).setDescription(subcommand.description);
subcommand.optionsInput.forEach(option => {
built[`add${option.type}Option`](subBuilt => {
subBuilt.setName(option.name).setDescription(option.description).setRequired(option.required);
if (option.choices === null || option.choices === undefined) {
throw new Error(`${this.customId} (${descriptionInput}) ${option.type} Option was nullish.`);
}
let choiceEntries = Object.entries(option.choices);
if (choiceEntries.length) {
subBuilt.addChoices(...Object.entries(option.choices));
}
return subBuilt;
})
})
return built;
})
})
this.data.setDefaultMemberPermissions()
}
};
module.exports.CommandWrapper = CommandWrapper;
class CommandWrapper extends module.exports.InteractionWrapper {
/** Additional wrapper properties for command parsing
* @param {string} customIdInput
* @param {string} descriptionInput
* @param {import("discord.js").PermissionFlags} defaultMemberPermission
* @param {boolean} isPremiumCommand
* @param {boolean} allowInDMsInput
* @param {number} cooldownInMS
* @param {{type: "Attachment" | "Boolean" | "Channel" | "Integer" | "Mentionable" | "Number" | "Role" | "String" | "User", name: string, description: string, required: boolean, choices: { name: string, value }[]}[]} optionsInput
* @param {{name: string, description: string, optionsInput: {type: "Attachment" | "Boolean" | "Channel" | "Integer" | "Mentionable" | "Number" | "Role" | "String" | "User", name: string, description: string, required: boolean, choices: { name: string, value }[]}}[]} subcommandsInput
* @param {(interaction: import("discord.js").Interaction) => void} executeFunction
*/
constructor(customIdInput, descriptionInput, defaultMemberPermission, isPremiumCommand, allowInDMsInput, cooldownInMS, optionsInput, subcommandsInput, executeFunction) {
super(customIdInput, cooldownInMS, executeFunction);
this.description = descriptionInput;
this.premiumCommand = isPremiumCommand;
this.data = new SlashCommandBuilder()
.setName(customIdInput)
.setDescription(descriptionInput)
.setDefaultMemberPermissions(PermissionFlagsBits.ViewChannel)
.setDMPermission(allowInDMsInput);
console.log("inside wrapper", this.data);
optionsInput.forEach(option => {
this.data[`add${option.type}Option`](built => {
built.setName(option.name).setDescription(option.description).setRequired(option.required);
if (option.choices === null || option.choices === undefined) {
throw new Error(`${this.customId} (${descriptionInput}) ${option.type} Option was nullish.`);
}
if (option.choices.length) {
built.addChoices(...option.choices);
}
return built;
})
})
subcommandsInput.forEach(subcommand => {
this.data.addSubcommand(built => {
built.setName(subcommand.name).setDescription(subcommand.description);
subcommand.optionsInput.forEach(option => {
built[`add${option.type}Option`](subBuilt => {
subBuilt.setName(option.name).setDescription(option.description).setRequired(option.required);
if (option.choices === null || option.choices === undefined) {
throw new Error(`${this.customId} (${descriptionInput}) ${option.type} Option was nullish.`);
}
let choiceEntries = Object.entries(option.choices);
if (choiceEntries.length) {
subBuilt.addChoices(...Object.entries(option.choices));
}
return subBuilt;
})
})
return built;
})
})
this.data.setDefaultMemberPermissions()
}
};
module.exports.CommandWrapper = CommandWrapper;
9 replies
DIAdiscord.js - Imagine an app
Created by Arcane_ish on 6/23/2023 in #djs-questions
Can't read default_member_permissions from SlashCommandBuilder?
9 replies