How do i send an embed as a slash command? #2936
Answered
by
jamesbt365
RealMrCactus
asked this question in
Q&A
-
this is all i could figure out. use serenity::all::Context;
use serenity::builder::CreateCommand;
use serenity::builder::{CreateEmbed, CreateEmbedFooter, CreateMessage};
use serenity::model::Timestamp;
pub fn run(ctx: Context) -> Result<(), serenity::Error> {
let footer = CreateEmbedFooter::new("This is a footer");
let embed = CreateEmbed::new()
.title("This is a title")
.description("This is a description")
.fields(vec![
("This is the first field", "This is a field body", true),
("This is the second field", "Both fields are inline", true),
])
.field("This is the third field", "This is not an inline field", false)
.footer(footer)
// Add a timestamp for the current time
// This also accepts a rfc3339 Timestamp
.timestamp(Timestamp::now());
let builder = CreateMessage::new()
.content("Hello, World!")
.embed(embed);
Ok(())
}
pub fn register() -> CreateCommand {
CreateCommand::new("embed").description("Embeds a message")
} |
Beta Was this translation helpful? Give feedback.
Answered by
jamesbt365
Aug 8, 2024
Replies: 1 comment
-
It is much easier for you to use poise, but if you really don't want to, and haven't already, check out the example for doing slash commands in serenity. Doing it directly in serenity is not pretty by any means, you have to:
It certainly isn't pretty, but if you don't want to use poise that is how you have to do it. See the example for a full rundown. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jamesbt365
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is much easier for you to use poise, but if you really don't want to, and haven't already, check out the example for doing slash commands in serenity.
Doing it directly in serenity is not pretty by any means, you have to:
InteractionCreate
event, match the enum forCommandInteraction
create_response
method or thecreate_followup
method, depending on if you have already sent a response or not.It certainly isn't pretty, but if you don't want to use poise that is how you have to do it. See the example for a full rundown.