how to make bot handle external embed

How to handle embed created by external app? - I wish to send an embed on behalf of the bot, thru my custom game (with btn components etc). - I want my bot client to be able to handle those responses. how do i do that? basically: create embed from game, handle it thru bot
22 Replies
d.js toolkit
d.js toolkit4mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Somebody
Somebody4mo ago
What's your exact discord.js npm list discord.js and node node -v version? 14.14.1 already mentioned
duck
duck4mo ago
I wish to send an embed on behalf of the bot, thru my custom game (with btn components etc).
I'm not fully sure what you mean by this if your bot is what's handling the game, your bot can just send these messages
I want my bot client to be able to handle those responses.
if you're referring to handling the components, components are handled via interactions (guide below) if you're simply looking to receive and respond to messages being sent by something else (in case your bot isn't what's handling the game), all messages can be handled via the messageCreate event
d.js docs
d.js docs4mo ago
:guide: Message Components: Buttons read more :guide: Message Components: Component interactions read more
Somebody
Somebody4mo ago
i know how to use components. so let me make it simple: is there a way to interact with the bot thru my game? - some action happens in game - i call some webhook or idk and it triggers some function in bot
Somebody
Somebody4mo ago
No description
Somebody
Somebody4mo ago
this thing, i can make it by typing a command but i also want to be able to make it from my game now ican prolly do so via webhooks, but not sure how would i go about handling those interactions from the bot (eg: interaction when i click respond) i hope i explained it better, english is not my native lang
duck
duck4mo ago
these are some incredibly vague questions, but just focusing on this image, webhooks created by a bot can send message components the interactions are sent as normal to the bot that created the webhook for a broader functionality of "trigger some function in bot" that doesn't involve sending a message, you'd need to set up your own webhook api for your bot
Somebody
Somebody4mo ago
uhm like express or something?
duck
duck4mo ago
sure
Somebody
Somebody4mo ago
i think that isn't idea for my bot since i cant expose ports sadlyy i basically wanted to be able to login as bot thru my game, if possible somehow and then send this embed that would solve my issue
duck
duck4mo ago
I have no idea how your game works, so I can't say anything regarding logging in but your bot is able to just send messages whenever it likes (within reason for rate limits)
Somebody
Somebody4mo ago
i'd assume i'd have to use some raw discord api? (not discord.js) 🤔
duck
duck4mo ago
no, your bot can send messages through discord.js
d.js docs
d.js docs4mo ago
:method: TextChannel#send() Sends a message to this channel.
Somebody
Somebody4mo ago
i know but it can only send it via: - the client my bot is running on - a user interaction nothin else uhm im not a total newbie, i can do the basics
duck
duck4mo ago
that's great, but every question you ask is incredibly vague, and I have no concept of what you know and what you don't know since you haven't given me very much information to work with
Somebody
Somebody4mo ago
i'll try to explain: - I can create embeds using a discord webhook (basically discord api) - I can send embeds directly thru bot 1. my bot can responds to interactions from embeds sent thru itself 2. my bot can (possibly) NOT respond to interactions to the embed from webhook is my point 2 possible?
duck
duck4mo ago
as mentioned previously, webhooks created by bots can send message components the interactions for these components are sent to the bot that created them as normal which is to say, yes 2 is possible
Somebody
Somebody4mo ago
ohhh, i'll try that thanks
! F ɪ  ʀ E  ✯
:rs_sad: someone come in my tick and also help me to ohk
Somebody
Somebody4mo ago
well its samp, written in pawn basically a server its unnecessary. However it was solved by creating the component using the webhook from my app (which the bot created btw) later i got the bot to respond to it (as it would normally) Here's how i created the component:
$jsonBody = '{
"components": [
{
"type": 1,
"components": [
{
"style": 1,
"label": "test",
"custom_id": "row_0_button_0",
"disabled": false,
"type": 2
}
]
}
]
}'

Invoke-RestMethod -Uri $webhookUrl -Method Post -Body $jsonBody -ContentType "application/json"
$jsonBody = '{
"components": [
{
"type": 1,
"components": [
{
"style": 1,
"label": "test",
"custom_id": "row_0_button_0",
"disabled": false,
"type": 2
}
]
}
]
}'

Invoke-RestMethod -Uri $webhookUrl -Method Post -Body $jsonBody -ContentType "application/json"
Here's how i handled the event in bot:
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isButton()) return; // Ignore interactions that are not buttons
console.log("button interaction recieved.")
// Check if the button is the one you're interested in
if (interaction.customId === 'row_0_button_0') {
console.log("responding to button interaction.")
// Reply to the interaction
await interaction.reply('You clicked the button!');
}
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isButton()) return; // Ignore interactions that are not buttons
console.log("button interaction recieved.")
// Check if the button is the one you're interested in
if (interaction.customId === 'row_0_button_0') {
console.log("responding to button interaction.")
// Reply to the interaction
await interaction.reply('You clicked the button!');
}
});
thank you^
Want results from more Discord servers?
Add your server
More Posts