nice-chef-4188
04/18/2023, 4:27 AMrust
let embed = Embed::fake(|e| {
e.title("Embed title").description("Rust Bot commands").field(
"hello",
"help",
false,
)
});
if msg.content == prefix.to_owned() + "help" {
if let Err(e) = msg.channel_id.say(&ctx.http, embed).await {
error!("Error sending message: {:?}", e);
}
}
Which as you know creates a fake one and sends it.
How do you create a real one?enough-oil-62271
04/18/2023, 4:39 AMnice-chef-4188
04/18/2023, 4:41 AMnice-chef-4188
04/18/2023, 4:41 AMenough-oil-62271
04/18/2023, 4:41 AMenough-oil-62271
04/18/2023, 4:41 AMnice-chef-4188
04/18/2023, 4:41 AMnice-chef-4188
04/18/2023, 4:46 AMrust
pub async fn send_embed(&self title: impl ToString, body: impl ToString, colour: Option<Colour>) -> Result<Message, SerenityError> {
info!("Sending embed `{}` with content `{}`", title.to_string(), body.to_string());
self.channel_id.send_message(&self.http, |msg| {
msg.embed(|embed| embed.title(title).description(body).colour(colour.unwrap_or(Colour::PURPLE)))
}).await
}
gives me this error
[{
"resource": "/d:/Users/Arad/Desktop/rustbot/src/main.rs",
"owner": "rustc",
"code": {
"value": "Click for full compiler diagnostic",
"target": {
"$mid": 1,
"path": "/diagnostic message [4]",
"scheme": "rust-analyzer-diagnostics-view",
"query": "4",
"fragment": "file:///d%3A/Users/Arad/Desktop/rustbot/src/main.rs"
}
},
"severity": 8,
"message": "`self` parameter is only allowed in associated functions\nassociated functions are those in `impl` or `trait` definitions",
"source": "rustc",
"startLineNumber": 13,
"startColumn": 25,
"endLineNumber": 13,
"endColumn": 30
}]enough-oil-62271
04/18/2023, 4:48 AMenough-oil-62271
04/18/2023, 4:49 AMnice-chef-4188
04/18/2023, 4:58 AMrust
async fn send_embed(
http: impl AsRef<serenity::http::Http>,
channel: ChannelId,
title: impl ToString,
body: impl ToString,
) -> Result<Message, SerenityError> {
info!("Sending embed `{}` with content `{}`", title.to_string(), body.to_string());
channel.send_message(http, |msg| {
msg.embed(|embed| {
embed.title(title).description(body).colour(Colour::PURPLE)
})
}).await
}
if msg.content == prefix.to_owned() + "help" {
send_embed(&ctx.http, msg.channel_id, "title", "body");
}
and it doesnt send anythingenough-oil-62271
04/18/2023, 5:01 AMgentle-ice-1561
04/18/2023, 10:31 AMnutritious-sugar-57720
04/18/2023, 5:55 PMrust
#[poise::command(slash_command)]
pub async fn suggest_qotd(
ctx: Context<'_>,
#[description = "Question"] question: String
) -> Result<(), Error> {
let channel = ctx.http().get_channel( /* Channel id */ ).await.unwrap();
if let Err(e) = channel.id().send_message(ctx.http(), |msg|{
msg.embed(|embed|{
embed.title("QOTD Suggestion")
.field("Question:", question, false)
.thumbnail("https://i.imgur.com/7tyrmrL.png")
.footer(|f|{
f.text(format!("Suggested by {x}#{y}", x = ctx.author().name, y = ctx.author().discriminator))
.icon_url(ctx.author().avatar_url().unwrap().to_string())
})
})
}).await{
// Handle error
} else {
// Handle error
}
Ok(())
}