Skip to content

Commit

Permalink
Fix examples 03, 14, and 17
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Jun 24, 2022
1 parent b5cb6a0 commit ab267b1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
12 changes: 8 additions & 4 deletions examples/e03_struct_utilities/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ impl EventHandler for Handler {
// In this case, you can direct message a User directly by simply
// calling a method on its instance, with the content of the
// message.
let dm = msg.author.dm(&context, |m| m.content("Hello!")).await;

if let Err(why) = dm {
println!("Error when direct messaging user: {:?}", why);
match msg.author.dm(&context).await {
Ok(create_message) => {
let msg = create_message.content("Hello!").execute(&context).await;
if let Err(why) = msg {
println!("Error when direct messaging user: {:?}", why);
}
},
Err(why) => println!("Error when direct messaging user: {:?}", why),
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions examples/e14_slash_commands/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::env;

use serenity::async_trait;
use serenity::builder::*;
use serenity::model::application::command::{Command, CommandOptionType};
use serenity::model::application::interaction::application_command::CommandDataOptionValue;
use serenity::model::application::interaction::{Interaction, InteractionResponseType};
Expand Down Expand Up @@ -56,12 +57,12 @@ impl EventHandler for Handler {
_ => "not implemented :(".to_string(),
};

let data = CreateInteractionResponseData::default().content(content);
if let Err(why) = command
.create_interaction_response(&ctx.http, |response| {
response
.kind(InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|message| message.content(content))
})
.create_interaction_response()
.kind(InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(data)
.execute(&ctx.http)
.await
{
println!("Cannot respond to slash command: {}", why);
Expand Down
6 changes: 5 additions & 1 deletion src/model/channel/channel_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,11 @@ impl ChannelId {
/// Refer to the documentation for [`CreateMessage`] for more information regarding message
/// restrictions and requirements.
pub fn send_message<'a>(self) -> CreateMessage<'a> {
CreateMessage::new(self, None)
CreateMessage::new(
self,
#[cfg(feature = "cache")]
None,
)
}

/// Starts typing in the channel for an indefinite period of time.
Expand Down
6 changes: 5 additions & 1 deletion src/model/channel/guild_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,11 @@ impl GuildChannel {
/// Refer to the documentation for [`CreateMessage`] for more information regarding message
/// restrictions and requirements.
pub fn send_message<'a>(&self) -> CreateMessage<'a> {
CreateMessage::new(self.id, Some(self.guild_id))
CreateMessage::new(
self.id,
#[cfg(feature = "cache")]
Some(self.guild_id),
)
}

/// Starts typing in the channel for an indefinite period of time.
Expand Down

0 comments on commit ab267b1

Please sign in to comment.