-
Notifications
You must be signed in to change notification settings - Fork 94
/
channel_permissions.rs
45 lines (38 loc) · 1.55 KB
/
channel_permissions.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
extern crate discord;
use discord::model::{
permissions, ChannelId, PermissionOverwrite, PermissionOverwriteType, RoleId, UserId,
};
use discord::Discord;
use std::env;
fn main() {
// Log in to Discord using a bot token from the environment
let discord = Discord::from_bot_token(&env::var("DISCORD_TOKEN").expect("Expected token"))
.expect("login failed");
println!("Ready.");
// Create bitflags of the permissions to allow and deny
let allow = permissions::VOICE_CONNECT | permissions::VOICE_SPEAK;
let deny = permissions::VOICE_MUTE_MEMBERS | permissions::VOICE_MOVE_MEMBERS;
let channel_id = ChannelId(0); // the id of the channel to set permissions
// Permissions on a channel can be set for either a member or a role
//
// Setting the permissions for a member:
let user_id = UserId(0); // the id of the user to set permissions for
let target = PermissionOverwrite {
kind: PermissionOverwriteType::Member(user_id),
allow: allow,
deny: deny,
};
println!("{:?}", discord.create_permission(channel_id, target));
// Similarly, setting the permissions for a role:
let role_id = RoleId(0); // the id of the role to set permissions for
let target = PermissionOverwrite {
kind: PermissionOverwriteType::Role(role_id),
allow: allow,
deny: deny,
};
println!("{:?}", discord.create_permission(channel_id, target));
// Deleting all of the permissions for a role or member by passing in the
// channel id and target member or role:
let target = PermissionOverwriteType::Member(user_id);
println!("{:?}", discord.delete_permission(channel_id, target));
}