'Slash command permissions
I used this code to do slash command and everything worked fine but when I use permissions I get error I don't know where to add permissions .......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Permissions code I used :
const permissions = [ { id: '969008290208051201', type: 'ROLE', permission: true, }, ]; await command.permissions.add({ permissions })
The code :
client.on('ready', async () => {
console.log(`Logged in as: ${client.user?.tag}`)
const gulidId = '904512141283975179'
const gulid = client.guilds.cache.get(gulidId)
const permissions = [
{
id: '969008290208051201',
type: 'ROLE',
permission: true,
},
];
await command.permissions.add({ permissions })
let commands
if (gulid) {
commands = gulid.commands
}else {
commands = bot.appliction?.commands
}
commands?.create({
name: 'say',
description: 'say something you wanna me to repeat',
options: [
{
name: 'channel',
description : 'the channel you wanna me send the message in',
required: true,
type: discord_js_1.Constants.ApplicationCommandOptionTypes.CHANNEL
},
{
name: 'message',
description: 'the message',
required: true,
type: discord_js_1.Constants.ApplicationCommandOptionTypes.STRING
}
],
defaultPermission: false,
})
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) {
return
}
const { commandName, options} = interaction
if (commandName === 'say') {
const channel = options.getChannel('channel')
const message = options.getString('message')
channel.send(message)
interaction.reply({
content: `announcement has been sent to ${channel}`,
ephemeral: true,
})
}
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
