diff options
| author | Austin Hellyer <[email protected]> | 2016-11-26 10:32:01 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-26 10:32:01 -0800 |
| commit | 343f20d2aa18696b961b6e4b3b867b68da2ca717 (patch) | |
| tree | 0d6a4392c84be60bbba387d162f5ea62aa2f6e17 /examples/06_command_framework.rs | |
| parent | More widely support no-cache method compiles (diff) | |
| download | serenity-343f20d2aa18696b961b6e4b3b867b68da2ca717.tar.xz serenity-343f20d2aa18696b961b6e4b3b867b68da2ca717.zip | |
Add Cache::get_guild_channel
This is an 'extras'-enabled function to get a guild's channel. This will
allow a simple Option pattern match over the result, rather than working
with an Option<Channel<T>>.
Example of old code vs. new code, in the context of an event handler:
Old:
```rs
use serenity::cache::CACHE;
use serenity::model::Channel;
let cache = CACHE.read().unwrap();
let channel = match cache.get_channel(channel_id) {
Some(Channel::Guild(channel)) => channel,
Some(Channel::Private(_)) => {
context.say("Groups and DMs not supported")
.map_err(|x| println!("Err sending message: {:?}", why);
return;
},
None => {
context.say("Could not find channel")
.map_err(|x| println!("Err sending message: {:?}", x);
return;
},
}
```
New:
```rs
use serenity::cache::CACHE;
let cache = CACHE.read().unwrap();
let channel = match cache.get_guild_channel(channel_id) {
Some(channel) => channel,
None => {
context.say("Could not find channel")
.map_err(|x| println!("Err sending message: {:?}", x));
return;
},
};
```
Diffstat (limited to 'examples/06_command_framework.rs')
0 files changed, 0 insertions, 0 deletions