-
Yes, it's me again. :D How can we send components? (buttons.) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
According to the documentation, this should work, but it doesn't send a button (only the message). Maybe user accounts cannot send it? I don't know! Anyway, we wouldn't be able to listen to the events/webhooks so this is not that useful for this lib! msg = {
"content": "This is a message with components",
"components": [
{
"type": 1,
"components": [
{
"type": 2,
"label": "Click me!",
"style": 1,
"custom_id": "click_one"
}
]
}
]
}
await api.apiCall(`/channels/${cid}/messages`, msg, 'POST') |
Beta Was this translation helpful? Give feedback.
-
Based on my experience Users and Webhooks (User Webhooks) can't send it. In this comment I use bot for create Webhook so it can be P.s: You need to have Bot's index; // Node Module and Token
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./bconfig.json');
// Create a new Discord Client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent] });
// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
client.on("messageCreate", message => {
if ( message.content === "create_webhook_byDeadLyBro#5730" && message.member.permissions.has('Administrator') ) {
message.channel.createWebhook({
name: "Some-username", // Webhook's username (required)
avatar: 'https://i.imgur.com/AfFp7pu.png', // Webhook's Profile Picture (required)
})
.then(webhook => console.log(`Created webhook ${webhook},\nWebhook URL: ${webhook.url}`)) // Log Webhook URL console after creating Webhook. We need this URL Copy it.
.catch(console.error); // If there is an error log that.
}
})
// Log in to Discord with your client's token
client.login(token); Bot's config { "token": "YOUR_BOT_TOKEN_HERE" } Usage for creating Webhook's index const { EmbedBuilder, WebhookClient, ButtonBuilder } = require('discord.js');
const { webhookId, webhookToken } = require('./wconfig.json');
const webhookClient = new WebhookClient({ id: webhookId, token: webhookToken });
const randomize = Math.random() * 16777215) + 1;
const embed = new EmbedBuilder()
.setTitle('TITLE') // Title
.setColor(randomize) // Randomize the color
.setDescription('DESCRIPTION') // Description
.setImage('IMAGE_URL') // Image URL
.setURL('https://example.com') // URL for Title
const button = new ButtonBuilder({
type: 2, // 2 for Button
style: 1,
// Button style, color;
// 1: Primary, Blurple
// 2: Secondary, Grey
// 3: Success, Green
// 4: Danger/Destructive, Red
// => Required field: `custom_id`. ( you can't use 'url' field if you use `custom_id` )
// 5: Link, Grey
// => Required field: `url`.
label: "Some Label", // Button Label
custom_id: "click_one", // Custom ID for Button if you use this you cant use url or reverse.
// url: "https://example.com" // Button URL
})
webhookClient.send({
content: `Message Content`, // Message Content
username: 'Username', // Username for Webhook, you can use yours lol
avatarURL: 'Avatar URL', // Avatar URL for Webhook, you can use yours lol
// embeds: [embed], // Embed (optional)
components: [ {
"type": 1, // Action Row, don't change this.
"components": [button.data] // A Component
}],
}).then(result => {
console.log(result) // Log results to console, terminal or whatever.
}); Webhook's {
"webhookId": "WEBHOOKS_ID",
"webhookToken":"WEBHOOKS_TOKEN",
"url": "WEBHOOKS_URL_HERE"
} P.s: Paste your Explanation:
Sending a Message with Components; then boom your custom component is here, also you can use embed with it! |
Beta Was this translation helpful? Give feedback.
According to the documentation, this should work, but it doesn't send a button (only the message). Maybe user accounts cannot send it? I don't know!
Anyway, we wouldn't be able to listen to the events/webhooks so this is not that useful for this lib!