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 toolkit12mo 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.
someone
someone12mo ago
node -v : v16.16.0 discord.js: discord.js@13.16.0
Danial
Danial12mo ago
Show full error
someone
someone12mo ago
alright here so whenever i do a slash command it give this error
someone
someone12mo ago
someone
someone12mo ago
and in my terminal it says @Danial
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
someone
someone12mo ago
the terminal says this
someone
someone12mo ago
someone
someone12mo ago
whenever i do a slash command with my bot
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
someone
someone12mo ago
it says ReferenceError: interaction is not defined
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
someone
someone12mo ago
wdym you want the code?
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
someone
someone12mo ago
alright
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
someone
someone12mo ago
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
someone
someone12mo 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 User12mo ago
Message Not Public
Sign In & Join Server To View
someone
someone12mo ago
bro i did
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
someone
someone12mo ago
alr
if(!interaction.iscommand()) return
^

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

ReferenceError: interaction is not defined
trplnr
trplnr12mo ago
it says the error directly to u interaction is not defined
royc
royc12mo ago
where is handleButton getting called from
someone
someone12mo ago
interactioncreate
royc
royc12mo ago
and run?
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
royc
royc12mo 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 User12mo ago
Message Not Public
Sign In & Join Server To View
GuiguiBlocCraft
GuiguiBlocCraft12mo ago
This code part isn't in your module code You can check in your index.js, with line num in the error
someone
someone12mo ago
that is the error do you want me to show you my index.js? alr
Nightro-Fx
Nightro-Fx8mo ago
@Dinnerfork Ik this is kina late but... did it get solved in the end?