Permission system not working

Hello, I'm currently coding a steal command where you are able to add emojis. But the Permission system isnt working...
TypeError: interaction.client.permissionsIn is not a function
TypeError: interaction.client.permissionsIn is not a function
if (
!interaction.guild.me.permissions.has(
Permissions.FLAGS.MANAGE_EMOJIS
)
) {
return interaction.reply(
"I don't have permission to manage emojis in this server."
);
}
if (
!interaction.guild.me.permissions.has(
Permissions.FLAGS.MANAGE_EMOJIS
)
) {
return interaction.reply(
"I don't have permission to manage emojis in this server."
);
}
19 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna15mo ago
what version are you on? because thats v13 code not even v13 v12
Cgx
CgxOP15mo ago
ehm ups... Well, how to do it in the v14 then?
d.js docs
d.js docs15mo ago
guide Additional Information: Updating from v13 to v14 read moreguide Additional Information: Updating from v12 to v13 read more
Cgx
CgxOP15mo ago
Well, now i got an other error.
\node_modules\discord.js\src\structures\GuildMember.js:322
if (!channel) throw new DiscordjsError(ErrorCodes.GuildChannelResolve);
^

Error [GuildChannelResolve]: Could not resolve channel to a guild channel.
\node_modules\discord.js\src\structures\GuildMember.js:322
if (!channel) throw new DiscordjsError(ErrorCodes.GuildChannelResolve);
^

Error [GuildChannelResolve]: Could not resolve channel to a guild channel.
treble/luna
treble/luna15mo ago
show your code
Cgx
CgxOP15mo ago
const { SlashCommandBuilder } = require("@discordjs/builders");
const { Permissions } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("steal")
.setDescription("Add an emoji to the server")
.addStringOption((option) =>
option
.setName("emoji")
.setDescription("The emoji to add to the server")
.setRequired(true),
)
.setDMPermission(false),

async execute(interaction) {
const { options, member } = interaction;
const emoji = options.getString("emoji");

if (!emoji) {
return interaction.reply(
"No emoji provided. Please provide a valid Discord emoji."
);
}

const match = emoji.match(/^<a?:\w+:(\d+)>$/);
if (!match) {
return interaction.reply(
"Invalid emoji provided. Please provide a valid Discord emoji."
);
}

const emojiID = match[1];
const isAnimated = emoji.startsWith("<a:");

if (!member.permissionsIn(interaction.guildId).has("MANAGE_EMOJIS")) {
return interaction.reply(
"You don't have permission to manage emojis in this server."
);
}

try {
const response = await fetch(
`https://cdn.discordapp.com/emojis/${emojiID}.${
isAnimated ? "gif" : "png"
}`
);
const emojiBuffer = await response.buffer();

await interaction.guild.emojis.create({
name: emoji.split(":")[1],
image: { source: emojiBuffer },
reason: `Emoji added by ${interaction.user.tag}`,
});

interaction.reply(`Emoji ${emoji} has been added to the server!`);
} catch (error) {
console.error(error);
interaction.reply(
"An error occurred while adding the emoji to the server."
);
}
},
};
const { SlashCommandBuilder } = require("@discordjs/builders");
const { Permissions } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("steal")
.setDescription("Add an emoji to the server")
.addStringOption((option) =>
option
.setName("emoji")
.setDescription("The emoji to add to the server")
.setRequired(true),
)
.setDMPermission(false),

async execute(interaction) {
const { options, member } = interaction;
const emoji = options.getString("emoji");

if (!emoji) {
return interaction.reply(
"No emoji provided. Please provide a valid Discord emoji."
);
}

const match = emoji.match(/^<a?:\w+:(\d+)>$/);
if (!match) {
return interaction.reply(
"Invalid emoji provided. Please provide a valid Discord emoji."
);
}

const emojiID = match[1];
const isAnimated = emoji.startsWith("<a:");

if (!member.permissionsIn(interaction.guildId).has("MANAGE_EMOJIS")) {
return interaction.reply(
"You don't have permission to manage emojis in this server."
);
}

try {
const response = await fetch(
`https://cdn.discordapp.com/emojis/${emojiID}.${
isAnimated ? "gif" : "png"
}`
);
const emojiBuffer = await response.buffer();

await interaction.guild.emojis.create({
name: emoji.split(":")[1],
image: { source: emojiBuffer },
reason: `Emoji added by ${interaction.user.tag}`,
});

interaction.reply(`Emoji ${emoji} has been added to the server!`);
} catch (error) {
console.error(error);
interaction.reply(
"An error occurred while adding the emoji to the server."
);
}
},
};
treble/luna
treble/luna15mo ago
was this command ran in dm? and do you have the Guilds intent
Cgx
CgxOP15mo ago
I have
No description
Cgx
CgxOP15mo ago
nope, in a server
treble/luna
treble/luna15mo ago
oh wait permissionsIn takes a channel iirc
d.js docs
d.js docs15mo ago
method GuildMember#permissionsIn() Returns channel.permissionsFor(guildMember). Returns permissions for a member in a guild channel, taking into account roles and permission overwrites.
Cgx
CgxOP15mo ago
uhm oh... Well what can i use instead of it?
treble/luna
treble/luna15mo ago
<GuildMember>.permissions
d.js docs
d.js docs15mo ago
property GuildMember#permissions The overall set of permissions for this member, taking only roles and owner status into account
Cgx
CgxOP15mo ago
that seemed to work! Well now i got another error....
treble/luna
treble/luna15mo ago
and that is
Cgx
CgxOP15mo ago
try {
// Fetch the emoji image
const response = await fetch(
`https://cdn.discordapp.com/emojis/${emojiID}.${
isAnimated ? "gif" : "png"
}`
);
const emojiBuffer = await response.arrayBuffer();

// Upload the emoji to the server
await interaction.guild.emojis.create({
name: emoji.split(":")[1],
image: { source: Buffer.from(emojiBuffer) },
reason: `Emoji added by ${interaction.user.tag}`,
});
try {
// Fetch the emoji image
const response = await fetch(
`https://cdn.discordapp.com/emojis/${emojiID}.${
isAnimated ? "gif" : "png"
}`
);
const emojiBuffer = await response.arrayBuffer();

// Upload the emoji to the server
await interaction.guild.emojis.create({
name: emoji.split(":")[1],
image: { source: Buffer.from(emojiBuffer) },
reason: `Emoji added by ${interaction.user.tag}`,
});
No description
d.js docs
d.js docs15mo ago
method GuildEmojiManager#create() Creates a new custom emoji in the guild.
Want results from more Discord servers?
Add your server