ReferenceError: interaction is not defined

DiscordAPIError: Invalid Form Body error when i load my slash commands into my discord bot
34 Replies
d.js toolkit
d.js toolkit•3y ago
• 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.
glitchdetected1
glitchdetected1OP•3y ago
node -v : v16.16.0 discord.js: discord.js@13.16.0
Danial
Danial•3y ago
Show full error
glitchdetected1
glitchdetected1OP•3y ago
alright here so whenever i do a slash command it give this error
glitchdetected1
glitchdetected1OP•3y ago
glitchdetected1
glitchdetected1OP•3y ago
and in my terminal it says @Danial
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
glitchdetected1
glitchdetected1OP•3y ago
the terminal says this
glitchdetected1
glitchdetected1OP•3y ago
glitchdetected1
glitchdetected1OP•3y ago
whenever i do a slash command with my bot
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
glitchdetected1
glitchdetected1OP•3y ago
it says ReferenceError: interaction is not defined
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
glitchdetected1
glitchdetected1OP•3y ago
wdym you want the code?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
glitchdetected1
glitchdetected1OP•3y ago
alright
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
glitchdetected1
glitchdetected1OP•3y ago
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
glitchdetected1
glitchdetected1OP•3y ago
here is the code
module.exports = {
name: "interactionCreate",
run: async (bot, interaction) => {
if (interaction.isCommand()) handleSlashCommand(bot, interaction)
else if (interaction.isButton()) handleButton(bot, interaction)
},
}

const handleButton = (bot, interaction) => {
const {client} = bot

// "name-param1-param2-...."
const [name, ...params] = interaction.customId.split("-")

const button = client.buttons.get(name)

if (!button) return
button.run(client, interaction, params)
}

const handleSlashCommand = (bot, interaction) => {
const {client} = bot
console.log('1')
if (!interaction.inGuild()) return interaction.reply("This command can only be used in a guild")

const slashcmd = client.slashcommands.get(interaction.commandName)

if (!slashcmd) return

// check permissions
if (slashcmd.perms && !interaction.member.permissions.has(slashcmd.perms))
return interaction.reply("You do not have permission to use this command")

slashcmd.run(client, interaction)
}
module.exports = {
name: "interactionCreate",
run: async (bot, interaction) => {
if (interaction.isCommand()) handleSlashCommand(bot, interaction)
else if (interaction.isButton()) handleButton(bot, interaction)
},
}

const handleButton = (bot, interaction) => {
const {client} = bot

// "name-param1-param2-...."
const [name, ...params] = interaction.customId.split("-")

const button = client.buttons.get(name)

if (!button) return
button.run(client, interaction, params)
}

const handleSlashCommand = (bot, interaction) => {
const {client} = bot
console.log('1')
if (!interaction.inGuild()) return interaction.reply("This command can only be used in a guild")

const slashcmd = client.slashcommands.get(interaction.commandName)

if (!slashcmd) return

// check permissions
if (slashcmd.perms && !interaction.member.permissions.has(slashcmd.perms))
return interaction.reply("You do not have permission to use this command")

slashcmd.run(client, interaction)
}
@Danial
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
glitchdetected1
glitchdetected1OP•3y ago
bro i did
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
glitchdetected1
glitchdetected1OP•3y ago
alr
if(!interaction.iscommand()) return
^

ReferenceError: interaction is not defined
if(!interaction.iscommand()) return
^

ReferenceError: interaction is not defined
trplnr
trplnr•3y ago
it says the error directly to u interaction is not defined
royc
royc•3y ago
where is handleButton getting called from
glitchdetected1
glitchdetected1OP•3y ago
interactioncreate
royc
royc•3y ago
and run?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
royc
royc•3y ago
something is not right, if interaction is undefined yeah either stack trace or more code idk easiest way to get it right is debug interaction
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
GuiguiBlocCraft
GuiguiBlocCraft•3y ago
This code part isn't in your module code You can check in your index.js, with line num in the error
glitchdetected1
glitchdetected1OP•3y ago
that is the error do you want me to show you my index.js? alr
Nightro-Fx
Nightro-Fx•2y ago
@Dinnerfork Ik this is kina late but... did it get solved in the end?

Did you find this page helpful?