Interaction replying with string works but doesn't work when I return a button
Hey, I started creating a discord bot. It returns a link for the user to click on but it's pretty ugly so i wanted to move over to a button, but when I do this, I am not getting any errors in my console, but running the slash command gives me "An error has occurred." in discord.
Currently this works fine:
await interaction.reply({ content: 'Please log in on our website to sync your account: ' + url});
I copied the official discord.js example with plain strings to keep things simple but even that won't work. If I replace the above line with this I'll get the error:
11 Replies
- 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.
- Issue solved? Press the button!How do you handle the interactionCreate event?
App.js
Then in my sync.js (the name of my slashcommand)
I'd have thought loading shouldn't be the issue since replying with a string is working without a hitch?
thats not ypur interactionCreate eve't
My mistake, one second
I guess that explains my error message 😅 Forgot I even added that
I'll log that error out, one second
I dont see any button handler there
That'd be it then :D, I didn't know there was special handling needed but I will have a look through the docs
you can use the .isButton typeguard and then do your logic there
Is that typescript specific?
No
It does narrow your typings, but it also has the runtime effect of only returning true if the interaction is a button interaction
Okay I figured this out.
The example I gave you from the docs wasn't "true to life" as all I wanted to do was have a button with a URL which doesn't require any special interaction handling logic since it's just a button with a URL
The core issue was just that I didn't import the ButtonBuilder, ButtonStyle, etc and I was catching all the errors which I didn't realise so I never saw the true cause.
All fixed now, thanks all for your help 👍