TypeError: user.permissionsIn is not a function

if (userData.notifications.luckypic === true) {
try {
const userEmbed = new EmbedBuilder()
.setTitle('Lottery: Luckypic')
.setColor('Green')
.addFields(
{ name: '**You got**', value: `${randomAmt}:wl:`, inline: false },
)
.setTimestamp();

const dmChannel = await user.createDM();
// Check if the bot has permission to send messages
if (user.permissionsIn(dmChannel).has("SEND_MESSAGES")) {
dmChannel.send({ embeds: [userEmbed] });
} else {
return false;
}
} catch (error) {
console.error(`Failed to send DM to user ${userIds}:`, error);
}
}
if (userData.notifications.luckypic === true) {
try {
const userEmbed = new EmbedBuilder()
.setTitle('Lottery: Luckypic')
.setColor('Green')
.addFields(
{ name: '**You got**', value: `${randomAmt}:wl:`, inline: false },
)
.setTimestamp();

const dmChannel = await user.createDM();
// Check if the bot has permission to send messages
if (user.permissionsIn(dmChannel).has("SEND_MESSAGES")) {
dmChannel.send({ embeds: [userEmbed] });
} else {
return false;
}
} catch (error) {
console.error(`Failed to send DM to user ${userIds}:`, error);
}
}
5 Replies
d.js toolkit
d.js toolkit8mo 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! - Marked as resolved by OP
igzh
igzhOP8mo ago
can anyone help me i keep getting this error
NyR
NyR8mo ago
User needs to be instance of GuildMember, users do not have permissions, GuildMember do, also permissions are PascalCase on v14, so that won't work
d.js docs
d.js docs8mo ago
Despite sounding similar there is a distinct difference between users and members in Discord: - User: global Discord user data (global avatar, username, tag, id) - GuildMember: user data associated to a guild (guild, nickname, roles, voice, guild avatar, etc.) - Conversion: User ➞ GuildMember | GuildMember ➞ User * Note: Events received in cached guilds will often have both the member and user available, eg. interaction.user and interaction.member RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined - All SCREAMING_SNAKE_CASE enums have been changed to PascalCase - Intents: Intents.FLAGS.GUILD_MESSAGES -> GatewayIntentBits.GuildMessages - Permissions: Permissions.FLAGS.SEND_MESSAGES -> PermissionFlagsBits.SendMessages
igzh
igzhOP8mo ago
kk thanks
Want results from more Discord servers?
Add your server