#get interaction name

64 messages · Page 1 of 1 (latest)

low latch
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

soft citrusBOT
low latch
#

thanks!

#

how do i ban a member?

soft citrusBOT
wild jay
#

any of those 3 would do it

low latch
#

Okay

#

i will try it

#

thanks

#

to get the guildmember do i do targetMember or targetUser

#

forget it

low latch
#

interaction.targetMember?

#

works!

#

thanks very much i will do the same for kick and other stuff!

#

ur epic @wild jay

low latch
#

another problem i am having that i just saw

#

with the permissions

#

i am getting TypeError: Cannot read properties of undefined (reading 'Flags')

#

in this line

#

if (!interaction.member.permissions.has(PermissionsBitField.Flags.KickMember)) {

#

PermissionsBitField.Flags

wild jay
#

PermissionsBitField is undefined then

low latch
#

what version is PermissionsBitField intruduced in?

#

14?

wild jay
#

v14

#

yes

low latch
#

Okay

#

i think i might know why

#

i am using 14

#

just i think i forgot to change something in vs code

#

so turns out i updated incorrectly and i now updated and i get many errors like Interaction has already been acknowledged

#

and TypeError: command.execute is not a function

wild jay
#

for the first one, you are replying twice

#

for the second one, command has no execute method.

low latch
#

i have these

#
client.on('interactionCreate', interaction => {
    if (!interaction.isUserContextMenuCommand()) return;
    const { username } = interaction.targetUser;
    console.log(username);
    if (!interaction.commandName == "Ban") {
        return
    }
    if (!interaction.member.permissions.has(PermissionsBitField.Flags.BanMember)) {
        interaction.reply({ content: 'No Permission!', ephemeral: true});
        return;
    }
    interaction.targetMember.ban();
    interaction.reply({ content: 'Done', ephemeral: true});
    
});

client.on('interactionCreate', interaction => {
    if (!interaction.isUserContextMenuCommand()) return;
    const { username } = interaction.targetUser;
    console.log(username);
    if (!interaction.commandName == "Kick") {
        return
    }
    if (!interaction.member.permissions.has(PermissionsBitField.Flags.KickMember)) {
        interaction.reply({ content: 'No Permission!', ephemeral: true});
        return;
    }
    interaction.targetMember.kick();
    interaction.reply({ content: 'Done', ephemeral: true});
    
});
#

is this incorrect?

soft citrusBOT
#

Checking for things to not be equal in JavaScript:

- if (!yourVariable === yourOtherVariable) // !yourVariable is coerced to a boolean value
+ if (yourVariable !== yourOtherVariable) // checks that one is not equal to the other

• Comparison operators in JavaScript: learn more

low latch
#

so i just need to make it !==?

#

i now have this

#
    if (!interaction.isUserContextMenuCommand()) return;
    const { username } = interaction.targetUser;
    console.log(username);
    if (interaction.commandName !== "Ban") {
        return
    }
    if (!interaction.member.permissions.has(PermissionsBitField.Flags.BanMember)) {
        interaction.reply({ content: 'No Permission!', ephemeral: true});
        return;
    }
    interaction.targetMember.ban();
    interaction.reply({ content: 'Done', ephemeral: true});
    
});

client.on('interactionCreate', interaction => {
    if (!interaction.isUserContextMenuCommand()) return;
    const { username } = interaction.targetUser;
    console.log(username);
    if (interaction.commandName !== "Kick") {
        return
    }
    if (!interaction.member.permissions.has(PermissionsBitField.Flags.KickMember)) {
        interaction.reply({ content: 'No Permission!', ephemeral: true});
        return;
    }
    interaction.targetMember.kick();
    interaction.reply({ content: 'Done', ephemeral: true});
    
});```
#

still not fixed

#

is there a way to check if user has permission in 13v?

#

or i should just use 14v

#

and i am still getting Interaction has already been acknowledged.

#

i changed something its now this

#
    if (!interaction.isUserContextMenuCommand()) return;
    const { username } = interaction.targetUser;
    console.log(username);
    if (interaction.commandName === "Ban") {
        if (!interaction.member.permissions.has(PermissionsBitField.Flags.BanMember)) {
            interaction.reply({ content: 'No Permission!', ephemeral: true});
            return;
        }
        interaction.targetMember.ban();
        interaction.reply({ content: 'Done', ephemeral: true});
    
    }
    if (interaction.commandName === "Kick") {
        if (!interaction.member.permissions.has(PermissionsBitField.Flags.KickMember)) {
            interaction.reply({ content: 'No Permission!', ephemeral: true});
            return;
        }
        interaction.targetMember.kick();
        interaction.reply({ content: 'Done', ephemeral: true});
    }
    
    
});```
wild jay
#

you are replying twice

low latch
#

when am i replying twice

#

where in the code

#

all good!

#

fixed

#

and btw when the user dosent have perms he gets this error

#

RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined.

wild jay
#

BanMembers

#

KickMembers

low latch
#

Okay this is done! Thanks very much!

#

!close

wild jay