I am working on a feature in my Next.js app to add permission to new members access to specific private channels. I found a solution here but did not work in my application. I had given my bot essentially all the bot permission in general permission, as well as application.commands permission.
Whenever I call my api endpoint, however, it returns
Error updating channel permissions: { message: 'Missing Access', code: 50001 }
This is my current implementation below, an api call that takes in a user id and the channel id to which the user should have access to. Any help is appreciated.
import axios from "axios"
export default async function handler(req, res) {
const { channelId, userId } = req.body
const botToken = process.env.DISCORD_BOT_TOKEN
try {
const permissions = 0x400 | 0x800
const response = await axios.put(
`https://discord.com/api/v9/channels/${channelId}/permissions/${userId}`,
{
allow: permissions.toString(), // Convert numeric permission to string if needed
deny: "0", // Specify no permissions are denied as a string
type: 1, // Member type
},
{
headers: {
Authorization: `Bot ${botToken}`,
"Content-Type": "application/json",
},
}
)
return res.status(200).json({
success: true,
message: "Permissions updated successfully",
data: response.data,
})
} catch (error) {
console.error(
"Error updating channel permissions:",
error.response ? error.response.data : error.message
)
return res.status(500).json({
success: false,
message: "Failed to update channel permissions",
error: error.response ? error.response.data : { message: error.message },
})
}
}