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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#[cfg(feature = "http")]
use super::Builder;
#[cfg(feature = "http")]
use crate::http::CacheHttp;
#[cfg(feature = "http")]
use crate::internal::prelude::*;
use crate::model::prelude::*;
/// A builder which edits the properties of a [`Member`], to be used in conjunction with
/// [`Member::edit`].
///
/// [Discord docs](https://discord.com/developers/docs/resources/guild#modify-guild-member)
#[derive(Clone, Debug, Default, Serialize)]
#[must_use]
pub struct EditMember<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
nick: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
roles: Option<Vec<RoleId>>,
#[serde(skip_serializing_if = "Option::is_none")]
mute: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
deaf: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
channel_id: Option<Option<ChannelId>>,
#[serde(skip_serializing_if = "Option::is_none")]
communication_disabled_until: Option<Option<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
flags: Option<GuildMemberFlags>,
#[serde(skip)]
audit_log_reason: Option<&'a str>,
}
impl<'a> EditMember<'a> {
/// Equivalent to [`Self::default`].
pub fn new() -> Self {
Self::default()
}
/// Whether to deafen the member.
///
/// **Note**: Requires the [Deafen Members] permission.
///
/// [Deafen Members]: Permissions::DEAFEN_MEMBERS
pub fn deafen(mut self, deafen: bool) -> Self {
self.deaf = Some(deafen);
self
}
/// Whether to mute the member.
///
/// **Note**: Requires the [Mute Members] permission.
///
/// [Mute Members]: Permissions::MUTE_MEMBERS
pub fn mute(mut self, mute: bool) -> Self {
self.mute = Some(mute);
self
}
/// Changes the member's nickname. Pass an empty string to reset the nickname.
///
/// **Note**: Requires the [Manage Nicknames] permission.
///
/// [Manage Nicknames]: Permissions::MANAGE_NICKNAMES
pub fn nickname(mut self, nickname: impl Into<String>) -> Self {
self.nick = Some(nickname.into());
self
}
/// Set the list of roles that the member should have.
///
/// **Note**: Requires the [Manage Roles] permission to modify.
///
/// [Manage Roles]: Permissions::MANAGE_ROLES
pub fn roles(mut self, roles: impl IntoIterator<Item = impl Into<RoleId>>) -> Self {
self.roles = Some(roles.into_iter().map(Into::into).collect());
self
}
/// Move the member into a voice channel.
///
/// **Note**: Requires the [Move Members] permission.
///
/// [Move Members]: Permissions::MOVE_MEMBERS
#[inline]
pub fn voice_channel(mut self, channel_id: impl Into<ChannelId>) -> Self {
self.channel_id = Some(Some(channel_id.into()));
self
}
/// Disconnects the user from their voice channel, if any.
///
/// **Note**: Requires the [Move Members] permission.
///
/// [Move Members]: Permissions::MOVE_MEMBERS
pub fn disconnect_member(mut self) -> Self {
self.channel_id = Some(None);
self
}
/// Times the user out until `time`, an ISO8601-formatted datetime string.
///
/// `time` is considered invalid if it is not a valid ISO8601 timestamp or if it is greater
/// than 28 days from the current time.
///
/// **Note**: Requires the [Moderate Members] permission.
///
/// [Moderate Members]: Permissions::MODERATE_MEMBERS
#[doc(alias = "timeout")]
pub fn disable_communication_until(mut self, time: String) -> Self {
self.communication_disabled_until = Some(Some(time));
self
}
/// Times the user out until `time`.
///
/// `time` is considered invalid if it is greater than 28 days from the current time.
///
/// **Note**: Requires the [Moderate Members] permission.
///
/// [Moderate Members]: Permissions::MODERATE_MEMBERS
#[doc(alias = "timeout")]
pub fn disable_communication_until_datetime(self, time: Timestamp) -> Self {
self.disable_communication_until(time.to_string())
}
/// Allow a user to communicate, removing their timeout, if there is one.
///
/// **Note**: Requires the [Moderate Members] permission.
///
/// [Moderate Members]: Permissions::MODERATE_MEMBERS
#[doc(alias = "timeout")]
pub fn enable_communication(mut self) -> Self {
self.communication_disabled_until = Some(None);
self
}
pub fn flags(mut self, flags: GuildMemberFlags) -> Self {
self.flags = Some(flags);
self
}
/// Sets the request's audit log reason.
pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
self.audit_log_reason = Some(reason);
self
}
}
#[cfg(feature = "http")]
#[async_trait::async_trait]
impl Builder for EditMember<'_> {
type Context<'ctx> = (GuildId, UserId);
type Built = Member;
/// Edits the properties of the guild member.
///
/// For details on permissions requirements, refer to each specific method.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
async fn execute(
self,
cache_http: impl CacheHttp,
ctx: Self::Context<'_>,
) -> Result<Self::Built> {
cache_http.http().edit_member(ctx.0, ctx.1, &self, self.audit_log_reason).await
}
}