Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Message API send messages without components or embeds #6563

Closed
harshpandey002 opened this issue Dec 5, 2023 · 2 comments
Closed
Labels
bug message components click click click click click click click

Comments

@harshpandey002
Copy link

harshpandey002 commented Dec 5, 2023

Description

I have a bot installed in multiple guilds. I am creating a nextjs dashboard for server admins who can send messages with components and embeds to any channel in their guild through my bot.

When I try to send message with components and embeds, the message only shows up with the content and not components or embeds.

The response from /channels/{channel.id}/messages contains empty components and embeds.

Steps to Reproduce

  1. Create a bot
  2. Install it in your discord server
  3. Inside of a Nextjs app, use the same bot credentials to send message to discord
  4. Use /channels/{channel.id}/messages rest api to send message with components and embeds.

API call

 const res = await axios.post(
      `https://discord.com/api/v10/channels/{channel.id}/messages`,
      {
        content: 'Hello there!',
        tts: false,
        components: [
          {
            type: 1,
            components: [
              {
                type: 2,
                style: 1,
                label: 'Create your Submission',
                custom_id: `button_click`,
                disabled: false,
              },
            ],
          },
        ],
      },
      {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
          Accept: 'application/json',
          Authorization: `Bot ${process.env.NEXT_PUBLIC_DISCORD_BOT_TOKEN}`,
        },
      }
    );

Expected Behavior

Message should show up like this with a button

Screenshot 2023-12-06 at 12 49 56 AM

Current Behavior

But it shows up with just the content and no buttons

Screenshot 2023-12-06 at 12 51 32 AM

Screenshots/Videos

No response

Client and System Information

Bot is running up with discordjs and on the web I'm using Discord rest apis with same bot token and client id to send the message as the bot.

Link to the doc:
https://discord.com/developers/docs/resources/channel#create-message

@harshpandey002 harshpandey002 added bug message components click click click click click click click labels Dec 5, 2023
@MinnDevelopment
Copy link
Contributor

Have you tried sending json instead of urlencoded form data?

@harshpandey002
Copy link
Author

8+ hours of debugging and this was the issue, this is the reason I don't get hired 😭
Thank you @MinnDevelopment so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug message components click click click click click click click
Projects
None yet
Development

No branches or pull requests

2 participants