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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
|
use serde_json::builder::ObjectBuilder;
use std::collections::HashMap;
use std::io::Read;
use std::sync::{Arc, Mutex};
use super::connection::Connection;
use super::http;
use super::login_type::LoginType;
use ::utils::builder::{
CreateEmbed,
CreateInvite,
CreateMessage,
EditChannel,
EditGuild,
EditMember,
EditProfile,
EditRole,
GetMessages
};
use ::internal::prelude::*;
use ::model::*;
use ::utils;
#[cfg(feature = "state")]
use super::STATE;
/// The context is a general utility struct provided on event dispatches, which
/// helps with dealing with the current "context" of the event dispatch,
/// and providing helper methods where possible. The context also acts as a
/// general high-level interface over the associated [`Connection`] which
/// received the event, or the low-level [`http`] module.
///
/// For example, when the [`Client::on_message`] handler is dispatched to, the
/// context will contain the Id of the [`Channel`] that the message was created
/// for. This allows for using shortcuts like [`say`], which will
/// post its given argument to the associated channel for you as a [`Message`].
///
/// Additionally, the context contains "shortcuts", like for interacting with
/// the connection. Methods like [`set_game`] will unlock the connection and
/// perform an update for you to save a bit of work.
///
/// A context will only live for the event it was dispatched for. After the
/// event handler finished, it is destroyed and will not be re-used.
///
/// # Automatically using the State
///
/// The context makes use of the [`State`] being global, and will first check
/// the state for associated data before hitting the REST API. This is to save
/// Discord requests, and ultimately save your bot bandwidth and time. This also
/// acts as a clean interface for retrieving from the state without needing to
/// check it yourself first, and then performing a request if it does not exist.
/// The context ultimately acts as a means to simplify these two operations into
/// one.
///
/// For example, if you are needing information about a
/// [channel][`PublicChannel`] within a [guild][`LiveGuild`], then you can
/// use [`get_channel`] to retrieve it. Under most circumstances, the guild and
/// its channels will be cached within the state, and `get_channel` will just
/// pull from the state. If it does not exist, it will make a request to the
/// REST API, and then insert a clone of the channel into the state, returning
/// you the channel.
///
/// In this scenario, now that the state has the channel, performing the same
/// request to `get_channel` will instead pull from the state, as it is now
/// cached.
///
/// [`Channel`]: ../model/enum.Channel.html
/// [`Client::on_message`]: struct.Client.html#method.on_message
/// [`Connection`]: struct.Connection.html
/// [`LiveGuild`]: ../model/struct.LiveGuild.html
/// [`Message`]: ../model/struct.Message.html
/// [`PublicChannel`]: ../model/struct.PublicChannel.html
/// [`State`]: ../ext/state/struct.State.html
/// [`get_channel`]: #method.get_channel
/// [`http`]: http/index.html
/// [`say`]: #method.say
/// [`set_game`]: #method.set_game
#[derive(Clone)]
pub struct Context {
channel_id: Option<ChannelId>,
/// The associated connection which dispatched the event handler.
///
/// Note that if you are sharding, in relevant terms, this is the shard
/// which received the event being dispatched.
pub connection: Arc<Mutex<Connection>>,
login_type: LoginType,
}
impl Context {
/// Create a new Context to be passed to an event handler.
///
/// There's no real reason to use this yourself. But the option is there.
/// Highly re-consider _not_ using this if you're tempted.
///
/// Or don't do what I say. I'm just a comment hidden from the generated
/// documentation.
#[doc(hidden)]
pub fn new(channel_id: Option<ChannelId>,
connection: Arc<Mutex<Connection>>,
login_type: LoginType) -> Context {
Context {
channel_id: channel_id,
connection: connection,
login_type: login_type,
}
}
/// Accepts the given invite.
///
/// Refer to the documentation for [`http::accept_invite`] for restrictions
/// on accepting an invite.
///
/// **Note**: Requires that the current user be a user account.
///
/// # Errors
///
/// Returns a [`ClientError::InvalidOperationAsBot`] if the current user is
/// a bot user.
///
/// [`ClientError::InvalidOperationAsBot`]: enum.ClientError.html#variant.InvalidOperationAsBot
/// [`Invite::accept`]: ../model/struct.Invite.html#method.accept
pub fn accept_invite(&self, invite: &str) -> Result<Invite> {
if self.login_type == LoginType::Bot {
return Err(Error::Client(ClientError::InvalidOperationAsBot));
}
let code = utils::parse_invite(invite);
http::accept_invite(code)
}
/// Mark a [`Channel`] as being read up to a certain [`Message`].
///
/// Refer to the documentation for [`http::ack_message`] for more
/// information.
///
/// # Errors
///
/// Returns a [`ClientError::InvalidOperationAsBot`] if this is a bot.
///
/// [`Channel`]: ../../model/enum.Channel.html
/// [`ClientError::InvalidOperationAsBot`]: ../enum.ClientError.html#variant.InvalidOperationAsUser
/// [`Message`]: ../../model/struct.Message.html
/// [`http::ack_message`]: http/fn.ack_message.html
pub fn ack<C, M>(&self, channel_id: C, message_id: M) -> Result<()>
where C: Into<ChannelId>, M: Into<MessageId> {
if self.login_type == LoginType::User {
return Err(Error::Client(ClientError::InvalidOperationAsUser));
}
http::ack_message(channel_id.into().0, message_id.into().0)
}
/// Ban a [`User`] from a [`Guild`], removing their messages sent in the
/// last X number of days.
///
/// Refer to the documentation for [`http::ban_user`] for more information.
///
/// **Note**: Requires that you have the [Ban Members] permission.
///
/// # Examples
///
/// Ban the user that sent a message for `7` days:
///
/// ```rust,ignore
/// // assuming you are in a context
/// context.ban_user(context.guild_id, context.message.author, 7);
/// ```
///
/// # Errors
///
/// Returns a [`ClientError::DeleteMessageDaysAmount`] if the number of days
/// given is over the maximum allowed.
///
/// [`ClientError::DeleteMessageDaysAmount`]: enum.ClientError.html#variant.DeleteMessageDaysAmount
/// [`Guild`]: ../model/struct.Guild.html
/// [`User`]: ../model/struct.User.html
/// [Ban Members]: ../model/permissions/constant.BAN_MEMBERS.html
pub fn ban<G, U>(&self, guild_id: G, user_id: U, delete_message_days: u8)
-> Result<()> where G: Into<GuildId>, U: Into<UserId> {
if delete_message_days > 7 {
return Err(Error::Client(ClientError::DeleteMessageDaysAmount(delete_message_days)));
}
http::ban_user(guild_id.into().0, user_id.into().0, delete_message_days)
}
/// Broadcast that you are typing to a channel for the next 5 seconds.
///
/// After 5 seconds, another request must be made to continue broadcasting
/// that you are typing.
///
/// This should rarely be used for bots, and should likely only be used for
/// signifying that a long-running command is still being executed.
///
/// # Examples
///
/// ```rust,ignore
/// // assuming you are in a context
/// context.broadcast_typing(context.channel_id);
/// ```
pub fn broadcast_typing<C>(&self, channel_id: C) -> Result<()>
where C: Into<ChannelId> {
http::broadcast_typing(channel_id.into().0)
}
/// Creates a [`PublicChannel`] in the given [`Guild`].
///
/// Refer to [`http::create_channel`] for more information.
///
/// **Note**: Requires the [Manage Channels] permission.
///
/// # Examples
///
/// Create a voice channel in a guild with the name `test`:
///
/// ```rust,ignore
/// use serenity::model::ChannelType;
///
/// context.create_channel(context.guild_id, "test", ChannelType::Voice);
/// ```
///
/// [`Guild`]: ../model/struct.Guild.html
/// [`PublicChannel`]: ../model/struct.PublicChannel.html
/// [`http::create_channel`]: http/fn.create_channel.html
/// [Manage Channels]: ../model/permissions/constant.MANAGE_CHANNELS.html
pub fn create_channel<G>(&self, guild_id: G, name: &str, kind: ChannelType)
-> Result<Channel> where G: Into<GuildId> {
let map = ObjectBuilder::new()
.insert("name", name)
.insert("type", kind.name())
.build();
http::create_channel(guild_id.into().0, map)
}
/// Creates an emoji in the given guild with a name and base64-encoded
/// image. The [`utils::read_image`] function is provided for you as a
/// simple method to read an image and encode it into base64, if you are
/// reading from the filesystem.
///
/// **Note**: Requires the [Manage Emojis] permission.
///
/// # Examples
///
/// See the [`EditProfile::avatar`] example for an in-depth example as to
/// how to read an image from the filesystem and encode it as base64. Most
/// of the example can be applied similarly for this method.
///
/// [`EditProfile::avatar`]: ../utils/builder/struct.EditProfile.html#method.avatar
/// [`utils::read_image`]: ../utils/fn.read_image.html
/// [Manage Emojis]: ../model/permissions/constant.MANAGE_EMOJIS.html
pub fn create_emoji<G>(&self, guild_id: G, name: &str, image: &str)
-> Result<Emoji> where G: Into<GuildId> {
let map = ObjectBuilder::new()
.insert("name", name)
.insert("image", image)
.build();
http::create_emoji(guild_id.into().0, map)
}
/// Creates a [`Guild`] with the data provided.
///
/// **Note**: This endpoint is usually only available for user accounts.
/// Refer to Discord's information for the endpoint [here][whitelist] for
/// more information. If you require this as a bot, re-think what you are
/// doing and if it _really_ needs to be doing this.
///
/// # Examples
///
/// Create a guild called `"test"` in the [US West region] with no icon:
///
/// ```rust,ignore
/// use serenity::model::Region;
///
/// context.create_guild("test", Region::UsWest, None);
/// ```
///
/// [`Guild`]: ../model/struct.Guild.html
/// [US West region]: ../model/enum.Region.html#variant.UsWest
/// [whitelist]: https://discordapp.com/developers/docs/resources/guild#create-guild
pub fn create_guild(&self, name: &str, region: Region, icon: Option<&str>)
-> Result<Guild> {
let map = ObjectBuilder::new()
.insert("icon", icon)
.insert("name", name)
.insert("region", region.name())
.build();
http::create_guild(map)
}
/// Creates an [`Integration`] for a [`Guild`].
///
/// **Note**: Requires the [Manage Guild] permission.
///
/// [`Guild`]: ../model/struct.Guild.html
/// [`Integration`]: ../model/struct.Integration.html
/// [Manage Guild]: ../model/permissions/constant.MANAGE_GUILD.html
pub fn create_integration<G, I>(&self,
guild_id: G,
integration_id: I,
kind: &str)
-> Result<()> where G: Into<GuildId>,
I: Into<IntegrationId> {
let integration_id = integration_id.into();
let map = ObjectBuilder::new()
.insert("id", integration_id.0)
.insert("type", kind)
.build();
http::create_guild_integration(guild_id.into().0, integration_id.0, map)
}
/// Creates an invite for the channel, providing a builder so that fields
/// may optionally be set.
///
/// See the documentation for the [`CreateInvite`] builder for information
/// on how to use this and the default values that it provides.
///
/// **Note**: Requires the [Create Invite] permission.
///
/// [`CreateInvite`]: ../utils/builder/struct.CreateInvite.html
/// [Create Invite]: ../model/permissions/constant.CREATE_INVITE.html
pub fn create_invite<C, F>(&self, channel_id: C, f: F) -> Result<RichInvite>
where C: Into<ChannelId>, F: FnOnce(CreateInvite) -> CreateInvite {
let map = f(CreateInvite::default()).0.build();
http::create_invite(channel_id.into().0, map)
}
/// Creates a [permission overwrite][`PermissionOverwrite`] for either a
/// single [`Member`] or [`Role`] within a [`Channel`].
///
/// Refer to the documentation for [`PermissionOverwrite`]s for more
/// information.
///
/// **Note**: Requires the [Manage Channels] permission.
///
/// # Examples
///
/// Creating a permission overwrite for a member by specifying the
/// [`PermissionOverwrite::Member`] variant, allowing it the [Send Messages]
/// permission, but denying the [Send TTS Messages] and [Attach Files]
/// permissions:
///
/// ```rust,ignore
/// use serenity::model::{ChannelId, PermissionOverwrite, permissions};
///
/// // assuming you are in a context
///
/// let channel_id = 7;
/// let user_id = 8;
///
/// let allow = permissions::SEND_MESSAGES;
/// let deny = permissions::SEND_TTS_MESSAGES | permissions::ATTACH_FILES;
/// let overwrite = PermissionOverwrite {
/// allow: allow,
/// deny: deny,
/// kind: PermissionOverwriteType::Member(user_id),
/// };
///
/// let _result = context.create_permission(channel_id, overwrite);
/// ```
///
/// Creating a permission overwrite for a role by specifying the
/// [`PermissionOverwrite::Role`] variant, allowing it the [Manage Webhooks]
/// permission, but denying the [Send TTS Messages] and [Attach Files]
/// permissions:
///
/// ```rust,ignore
/// use serenity::model::{ChannelId, PermissionOverwrite, permissions};
///
/// // assuming you are in a context
///
/// let channel_id = 7;
/// let user_id = 8;
///
/// let allow = permissions::SEND_MESSAGES;
/// let deny = permissions::SEND_TTS_MESSAGES | permissions::ATTACH_FILES;
/// let overwrite = PermissionOverwrite {
/// allow: allow,
/// deny: deny,
/// kind: PermissionOverwriteType::Member(user_id),
/// };
///
/// let _result = context.create_permission(channel_id, overwrite);
/// ```
///
/// [`Channel`]: ../model/enum.Channel.html
/// [`Member`]: ../model/struct.Member.html
/// [`PermissionOverwrite`]: ../model/struct.PermissionOverWrite.html
/// [`PermissionOverwrite::Member`]: ../model/struct.PermissionOverwrite.html#variant.Member
/// [`Role`]: ../model/struct.Role.html
/// [Attach Files]: ../model/permissions/constant.ATTACH_FILES.html
/// [Manage Channels]: ../model/permissions/constant.MANAGE_CHANNELS.html
/// [Send TTS Messages]: ../model/permissions/constant.SEND_TTS_MESSAGES.html
pub fn create_permission<C>(&self,
channel_id: C,
target: PermissionOverwrite)
-> Result<()> where C: Into<ChannelId> {
let (id, kind) = match target.kind {
PermissionOverwriteType::Member(id) => (id.0, "member"),
PermissionOverwriteType::Role(id) => (id.0, "role"),
};
let map = ObjectBuilder::new()
.insert("allow", target.allow.bits())
.insert("deny", target.deny.bits())
.insert("id", id)
.insert("type", kind)
.build();
http::create_permission(channel_id.into().0, id, map)
}
/// Creates a direct message channel between the [current user] and another
/// [`User`]. This can also retrieve the channel if one already exists.
///
/// [`User`]: ../model/struct.User.html
/// [current user]: ../model/struct.CurrentUser.html
pub fn create_direct_message_channel<U>(&self, user_id: U)
-> Result<PrivateChannel> where U: Into<UserId> {
let map = ObjectBuilder::new()
.insert("recipient_id", user_id.into().0)
.build();
http::create_private_channel(map)
}
/// React to a [`Message`] with a custom [`Emoji`] or unicode character.
///
/// [`Message::react`] may be a more suited method of reacting in most
/// cases.
///
/// **Note**: Requires the [Add Reactions] permission, _if_ the current user
/// is the first user to perform a react with a certain emoji.
///
/// [`Emoji`]: ../model/struct.Emoji.html
/// [`Message`]: ../model/struct.Message.html
/// [`Message::react`]: ../model/struct.Message.html#method.react
/// [Add Reactions]: ../model/permissions/constant.ADD_REACTIONS.html
pub fn create_reaction<C, M, R>(&self,
channel_id: C,
message_id: M,
reaction_type: R)
-> Result<()>
where C: Into<ChannelId>,
M: Into<MessageId>,
R: Into<ReactionType> {
http::create_reaction(channel_id.into().0,
message_id.into().0,
reaction_type.into())
}
pub fn create_role<F, G>(&self, guild_id: G, f: F) -> Result<Role>
where F: FnOnce(EditRole) -> EditRole, G: Into<GuildId> {
let id = guild_id.into().0;
// The API only allows creating an empty role.
let role = try!(http::create_role(id));
let map = f(EditRole::default()).0.build();
http::edit_role(id, role.id.0, map)
}
/// Deletes a [`Channel`] based on the Id given.
///
/// If the channel being deleted is a [`PublicChannel`] (a [`Guild`]'s
/// channel), then the [Manage Channels] permission is required.
///
/// [`Channel`]: ../model/enum.Channel.html
/// [`Guild`]: ../model/struct.Guild.html
/// [`PublicChannel`]: ../model/struct.PublicChannel.html
/// [Manage Messages]: ../model/permissions/constant.MANAGE_CHANNELS.html
pub fn delete_channel<C>(&self, channel_id: C) -> Result<Channel>
where C: Into<ChannelId> {
http::delete_channel(channel_id.into().0)
}
/// Deletes an emoji in a [`Guild`] given its Id.
///
/// **Note**: Requires the [Manage Emojis] permission.
///
/// [`Guild`]: ../model/struct.Guild.html
/// [Manage Emojis]: ../model/permissions/constant.MANAGE_EMOJIS.html
pub fn delete_emoji<E, G>(&self, guild_id: G, emoji_id: E) -> Result<()>
where E: Into<EmojiId>, G: Into<GuildId> {
http::delete_emoji(guild_id.into().0, emoji_id.into().0)
}
/// Deletes a [`Guild`]. You must be the guild owner to be able to delete
/// the guild.
///
/// [`Guild`]: ../model/struct.Guild.html
pub fn delete_guild<G: Into<GuildId>>(&self, guild_id: G) -> Result<Guild> {
http::delete_guild(guild_id.into().0)
}
pub fn delete_integration<G, I>(&self, guild_id: G, integration_id: I)
-> Result<()> where G: Into<GuildId>, I: Into<IntegrationId> {
http::delete_guild_integration(guild_id.into().0,
integration_id.into().0)
}
/// Deletes the given invite.
///
/// Refer to the documentation for [`Invite::delete`] for restrictions on
/// deleting an invite.
///
/// # Errors
///
/// Returns a [`ClientError::InvalidPermissions`] if the current user does
/// not have the required [permission].
///
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [`Invite::delete`]: ../model/struct.Invite.html#method.delete
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
pub fn delete_invite(&self, invite: &str) -> Result<Invite> {
let code = utils::parse_invite(invite);
http::delete_invite(code)
}
/// Deletes a [`Message`] given its Id.
///
/// # Examples
///
/// Deleting every message that is received:
///
/// ```rust,ignore
/// use serenity::Client;
/// use std::env;
///
/// let client = Client::login_bot(&env::var("DISCORD_BOT_TOKEN").unwrap());
/// client.on_message(|context, message| {
/// context.delete_message(message);
/// });
/// ```
///
/// (in practice, please do not do this)
///
/// [`Message`]: ../model/struct.Message.html
pub fn delete_message<C, M>(&self, channel_id: C, message_id: M)
-> Result<()> where C: Into<ChannelId>, M: Into<MessageId> {
http::delete_message(channel_id.into().0, message_id.into().0)
}
pub fn delete_messages<C>(&self, channel_id: C, message_ids: &[MessageId])
-> Result<()> where C: Into<ChannelId> {
if self.login_type == LoginType::User {
return Err(Error::Client(ClientError::InvalidOperationAsUser))
}
let ids: Vec<u64> = message_ids.into_iter()
.map(|message_id| message_id.0)
.collect();
let map = ObjectBuilder::new()
.insert("messages", ids)
.build();
http::delete_messages(channel_id.into().0, map)
}
pub fn delete_note<U: Into<UserId>>(&self, user_id: U) -> Result<()> {
let map = ObjectBuilder::new()
.insert("note", "")
.build();
http::edit_note(user_id.into().0, map)
}
pub fn delete_permission<C>(&self,
channel_id: C,
permission_type: PermissionOverwriteType)
-> Result<()> where C: Into<ChannelId> {
let id = match permission_type {
PermissionOverwriteType::Member(id) => id.0,
PermissionOverwriteType::Role(id) => id.0,
};
http::delete_permission(channel_id.into().0, id)
}
/// Deletes the given [`Reaction`], but only if the current user is the user
/// who made the reaction or has permission to.
///
/// **Note**: Requires the [`Manage Messages`] permission, _if_ the current
/// user did not perform the reaction.
///
/// [`Reaction`]: ../model/struct.Reaction.html
/// [Manage Messages]: ../model/permissions/constant.MANAGE_MESSAGES.html
pub fn delete_reaction<C, M, R>(&self,
channel_id: C,
message_id: M,
user_id: Option<UserId>,
reaction_type: R)
-> Result<()>
where C: Into<ChannelId>,
M: Into<MessageId>,
R: Into<ReactionType> {
http::delete_reaction(channel_id.into().0,
message_id.into().0,
user_id.map(|uid| uid.0),
reaction_type.into())
}
pub fn delete_role<G, R>(&self, guild_id: G, role_id: R) -> Result<()>
where G: Into<GuildId>, R: Into<RoleId> {
http::delete_role(guild_id.into().0, role_id.into().0)
}
/// Sends a message to a user through a direct message channel. This is a
/// channel that can only be accessed by you and the recipient.
///
/// # Examples
///
/// There are three ways to send a direct message to someone, the first
/// being an unrelated, although equally helpful method.
///
/// Sending a message via [`User::dm`]:
///
/// ```rust,ignore
/// // assuming you are in a context
/// let _ = context.message.author.dm("Hello!");
/// ```
///
/// Sending a message to a `PrivateChannel`:
///
/// ```rust,ignore
/// assuming you are in a context
/// let private_channel = context.create_private_channel(context.message.author.id);
///
/// let _ = context.direct_message(private_channel, "Test!");
/// ```
///
/// Sending a message to a `PrivateChannel` given its ID:
///
/// ```rust,ignore
/// use serenity::Client;
/// use std::env;
///
/// let mut client = Client::login_bot(&env::var("DISCORD_BOT_TOKEN").unwrap());
///
/// client.on_message(|context, message| {
/// if message.content == "!pm-me" {
/// let channel = context.create_private_channel(message.author.id)
/// .unwrap();
///
/// let _ = channel.send_message("test!");
/// }
/// });
/// ```
///
/// [`PrivateChannel`]: ../model/struct.PrivateChannel.html
/// [`User::dm`]: ../model/struct.User.html#method.dm
pub fn dm<C: Into<ChannelId>>(&self, target_id: C, content: &str)
-> Result<Message> {
self.send_message(target_id.into(), |m| m.content(content))
}
pub fn edit_channel<C, F>(&self, channel_id: C, f: F)
-> Result<PublicChannel> where C: Into<ChannelId>,
F: FnOnce(EditChannel) -> EditChannel {
let channel_id = channel_id.into();
let map = match try!(self.get_channel(channel_id)) {
Channel::Public(channel) => {
let map = ObjectBuilder::new()
.insert("name", channel.name)
.insert("position", channel.position);
match channel.kind {
ChannelType::Text => map.insert("topic", channel.topic),
ChannelType::Voice => {
map.insert("bitrate", channel.bitrate)
.insert("user_limit", channel.user_limit)
},
kind => return Err(Error::Client(ClientError::UnexpectedChannelType(kind))),
}
},
Channel::Private(channel) => {
return Err(Error::Client(ClientError::UnexpectedChannelType(channel.kind)));
},
Channel::Group(_group) => {
return Err(Error::Client(ClientError::UnexpectedChannelType(ChannelType::Group)));
},
};
let edited = f(EditChannel(map)).0.build();
http::edit_channel(channel_id.0, edited)
}
pub fn edit_emoji<E, G>(&self, guild_id: G, emoji_id: E, name: &str)
-> Result<Emoji> where E: Into<EmojiId>, G: Into<GuildId> {
let map = ObjectBuilder::new()
.insert("name", name)
.build();
http::edit_emoji(guild_id.into().0, emoji_id.into().0, map)
}
pub fn edit_guild<F, G>(&self, guild_id: G, f: F) -> Result<Guild>
where F: FnOnce(EditGuild) -> EditGuild, G: Into<GuildId> {
let map = f(EditGuild::default()).0.build();
http::edit_guild(guild_id.into().0, map)
}
pub fn edit_member<F, G, U>(&self, guild_id: G, user_id: U, f: F)
-> Result<()> where F: FnOnce(EditMember) -> EditMember,
G: Into<GuildId>,
U: Into<UserId> {
let map = f(EditMember::default()).0.build();
http::edit_member(guild_id.into().0, user_id.into().0, map)
}
/// Edits the current user's nickname for the provided [`Guild`] via its Id.
///
/// Pass `None` to reset the nickname.
///
/// **Note**: Requires the [Change Nickname] permission.
///
/// [`Guild`]: ../../model/struct.Guild.html
/// [Change Nickname]: permissions/constant.CHANGE_NICKNAME.html
#[inline]
pub fn edit_nickname<G>(&self, guild_id: G, new_nickname: Option<&str>)
-> Result<()> where G: Into<GuildId> {
http::edit_nickname(guild_id.into().0, new_nickname)
}
pub fn edit_profile<F: FnOnce(EditProfile) -> EditProfile>(&mut self, f: F)
-> Result<CurrentUser> {
let user = try!(http::get_current_user());
let mut map = ObjectBuilder::new()
.insert("avatar", user.avatar)
.insert("username", user.name);
if let Some(email) = user.email.as_ref() {
map = map.insert("email", email);
}
let edited = f(EditProfile(map)).0.build();
http::edit_profile(edited)
}
pub fn edit_role<F, G, R>(&self, guild_id: G, role_id: R, f: F)
-> Result<Role> where F: FnOnce(EditRole) -> EditRole,
G: Into<GuildId>,
R: Into<GuildId> {
let guild_id = guild_id.into();
let role_id = role_id.into();
let map = feature_state! {{
let state = STATE.lock().unwrap();
let role = if let Some(role) = {
state.find_role(guild_id.0, role_id.0)
} {
role
} else {
return Err(Error::Client(ClientError::RecordNotFound));
};
f(EditRole::new(role)).0.build()
} else {
f(EditRole::default()).0.build()
}};
http::edit_role(guild_id.0, role_id.0, map)
}
/// Edit a message given its Id and the Id of the channel it belongs to.
///
/// Pass an empty string (`""`) to `text` if you are editing a message with
/// an embed but no content. Otherwise, `text` must be given.
pub fn edit_message<C, F, M>(&self, channel_id: C, message_id: M, text: &str, f: F)
-> Result<Message> where C: Into<ChannelId>,
F: FnOnce(CreateEmbed) -> CreateEmbed,
M: Into<MessageId> {
let map = ObjectBuilder::new()
.insert("content", text)
.insert("embed", Value::Object(f(CreateEmbed::default()).0))
.build();
http::edit_message(channel_id.into().0, message_id.into().0, map)
}
pub fn edit_note<U: Into<UserId>>(&self, user_id: U, note: &str)
-> Result<()> {
let map = ObjectBuilder::new()
.insert("note", note)
.build();
http::edit_note(user_id.into().0, map)
}
pub fn get_bans<G: Into<GuildId>>(&self, guild_id: G) -> Result<Vec<Ban>> {
http::get_bans(guild_id.into().0)
}
pub fn get_channel_invites<C: Into<ChannelId>>(&self, channel_id: C)
-> Result<Vec<RichInvite>> {
http::get_channel_invites(channel_id.into().0)
}
pub fn get_channel<C>(&self, channel_id: C) -> Result<Channel>
where C: Into<ChannelId> {
let channel_id = channel_id.into();
feature_state_enabled! {{
if let Some(channel) = STATE.lock().unwrap().find_channel(channel_id) {
return Ok(channel.clone())
}
}}
http::get_channel(channel_id.0)
}
pub fn get_channels<G>(&self, guild_id: G)
-> Result<HashMap<ChannelId, PublicChannel>> where G: Into<GuildId> {
let guild_id = guild_id.into();
feature_state_enabled! {{
let state = STATE.lock().unwrap();
if let Some(guild) = state.find_guild(guild_id) {
return Ok(guild.channels.clone());
}
}}
let mut channels = HashMap::new();
for channel in try!(http::get_channels(guild_id.0)) {
channels.insert(channel.id, channel);
}
Ok(channels)
}
pub fn get_emoji<E, G>(&self, guild_id: G, emoji_id: E) -> Result<Emoji>
where E: Into<EmojiId>, G: Into<GuildId> {
http::get_emoji(guild_id.into().0, emoji_id.into().0)
}
pub fn get_emojis<G: Into<GuildId>>(&self, guild_id: G)
-> Result<Vec<Emoji>> {
http::get_emojis(guild_id.into().0)
}
pub fn get_guild<G: Into<GuildId>>(&self, guild_id: G) -> Result<Guild> {
http::get_guild(guild_id.into().0)
}
pub fn get_guild_invites<G>(&self, guild_id: G) -> Result<Vec<RichInvite>>
where G: Into<GuildId> {
http::get_guild_invites(guild_id.into().0)
}
pub fn get_guild_prune_count<G>(&self, guild_id: G, days: u16)
-> Result<GuildPrune> where G: Into<GuildId> {
let map = ObjectBuilder::new()
.insert("days", days)
.build();
http::get_guild_prune_count(guild_id.into().0, map)
}
pub fn get_guilds(&self) -> Result<Vec<GuildInfo>> {
http::get_guilds()
}
pub fn get_integrations<G: Into<GuildId>>(&self, guild_id: G)
-> Result<Vec<Integration>> {
http::get_guild_integrations(guild_id.into().0)
}
pub fn get_invite(&self, invite: &str) -> Result<Invite> {
let code = utils::parse_invite(invite);
http::get_invite(code)
}
pub fn get_member<G, U>(&self, guild_id: G, user_id: U) -> Result<Member>
where G: Into<GuildId>, U: Into<UserId> {
let guild_id = guild_id.into();
let user_id = user_id.into();
feature_state_enabled! {{
let state = STATE.lock().unwrap();
if let Some(member) = state.find_member(guild_id, user_id) {
return Ok(member.clone());
}
}}
http::get_member(guild_id.0, user_id.0)
}
/// Retrieves a single [`Message`] from a [`Channel`].
///
/// Requires the [Read Message History] permission.
///
/// # Errors
///
/// Returns a [`ClientError::InvalidOperationAsUser`] if this is a user.
///
/// [`Channel`]: ../model/struct.Channel.html
/// [`ClientError::InvalidOperationAsUser`]: ../enum.ClientError.html#variant.InvalidOperationAsUser
/// [`Message`]: ../model/struct.Message.html
/// [Read Message History]: ../model/permissions/constant.READ_MESSAGE_HISTORY.html
pub fn get_message<C, M>(&self, channel_id: C, message_id: M)
-> Result<Message> where C: Into<ChannelId>, M: Into<MessageId> {
if self.login_type == LoginType::User {
return Err(Error::Client(ClientError::InvalidOperationAsUser))
}
http::get_message(channel_id.into().0, message_id.into().0)
}
pub fn get_messages<C, F>(&self, channel_id: C, f: F) -> Result<Vec<Message>>
where C: Into<ChannelId>, F: FnOnce(GetMessages) -> GetMessages {
let query = {
let mut map = f(GetMessages::default()).0;
let mut query = format!("?limit={}",
map.remove("limit").unwrap_or(50));
if let Some(after) = map.remove("after") {
query.push_str("&after=");
query.push_str(&after.to_string());
}
if let Some(around) = map.remove("around") {
query.push_str("&around=");
query.push_str(&around.to_string());
}
if let Some(before) = map.remove("before") {
query.push_str("&before=");
query.push_str(&before.to_string());
}
query
};
http::get_messages(channel_id.into().0, &query)
}
/// Retrieves the list of [`User`]s who have reacted to a [`Message`] with a
/// certain [`Emoji`].
///
/// The default `limit` is `50` - specify otherwise to receive a different
/// maximum number of users. The maximum that may be retrieve at a time is
/// `100`, if a greater number is provided then it is automatically reduced.
///
/// The optional `after` attribute is to retrieve the users after a certain
/// user. This is useful for pagination.
///
/// **Note**: Requires the [Read Message History] permission.
///
/// # Errors
///
/// Returns a [`ClientError::InvalidPermissions`] if the current user does
/// not have the required [permissions].
///
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [`Emoji`]: struct.Emoji.html
/// [`Message`]: struct.Message.html
/// [`User`]: struct.User.html
/// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
pub fn get_reaction_users<C, M, R, U>(&self,
channel_id: C,
message_id: M,
reaction_type: R,
limit: Option<u8>,
after: Option<U>)
-> Result<Vec<User>>
where C: Into<ChannelId>,
M: Into<MessageId>,
R: Into<ReactionType>,
U: Into<UserId> {
let limit = limit.map(|x| if x > 100 { 100 } else { x }).unwrap_or(50);
http::get_reaction_users(channel_id.into().0,
message_id.into().0,
reaction_type.into(),
limit,
after.map(|u| u.into().0))
}
/// Kicks a [`Member`] from the specified [`Guild`] if they are in it.
///
/// Requires the [Kick Members] permission.
///
/// [`Guild`]: ../model/struct.Guild.html
/// [`Member`]: ../model/struct.Member.html
/// [Kick Members]: ../model/permissions/constant.KICK_MEMBERS.html
pub fn kick_member<G, U>(&self, guild_id: G, user_id: U) -> Result<()>
where G: Into<GuildId>, U: Into<UserId> {
http::kick_member(guild_id.into().0, user_id.into().0)
}
pub fn leave_guild<G: Into<GuildId>>(&self, guild_id: G) -> Result<Guild> {
http::leave_guild(guild_id.into().0)
}
pub fn move_member<C, G, U>(&self, guild_id: G, user_id: U, channel_id: C)
-> Result<()> where C: Into<ChannelId>,
G: Into<ChannelId>,
U: Into<ChannelId> {
let map = ObjectBuilder::new()
.insert("channel_id", channel_id.into().0)
.build();
http::edit_member(guild_id.into().0, user_id.into().0, map)
}
/// Retrieves the list of [`Message`]s which are pinned to the specified
/// [`Channel`].
///
/// [`Channel`]: ../model/enum.Channel.html
/// [`Message`]: ../model/struct.Message.html
pub fn get_pins<C>(&self, channel_id: C) -> Result<Vec<Message>>
where C: Into<ChannelId> {
http::get_pins(channel_id.into().0)
}
pub fn pin<C, M>(&self, channel_id: C, message_id: M) -> Result<()>
where C: Into<ChannelId>, M: Into<MessageId> {
http::pin_message(channel_id.into().0, message_id.into().0)
}
/// Sends a message with just the given message content in the channel that
/// a message was received from.
///
/// **Note**: This will only work when a [`Message`] is received.
///
/// # Errors
///
/// Returns a [`ClientError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
/// Returns a [`ClientError::NoChannelId`] when there is no [`ChannelId`]
/// directly available.
///
/// [`ChannelId`]: ../../model/struct.ChannelId.html
/// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong
/// [`ClientError::NoChannelId`]: ../enum.ClientError.html#NoChannelId
/// [`Message`]: ../model/struct.Message.html
pub fn say(&self, content: &str) -> Result<Message> {
if let Some(channel_id) = self.channel_id {
self.send_message(channel_id, |m| m.content(content))
} else {
Err(Error::Client(ClientError::NoChannelId))
}
}
/// Sends a file along with optional message contents. The filename _must_
/// be specified.
///
/// Pass an empty string to send no message contents.
///
/// **Note**: Message contents must be under 2000 unicode code points.
///
/// # Errors
///
/// If the content of the message is over the above limit, then a
/// [`ClientError::MessageTooLong`] will be returned, containing the number
/// of unicode code points over the limit.
///
/// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong
pub fn send_file<C, R>(&self,
channel_id: C,
content: &str,
file: R,
filename: &str)
-> Result<Message> where C: Into<ChannelId>,
R: Read {
if let Some(length_over) = Message::overflow_length(content) {
return Err(Error::Client(ClientError::MessageTooLong(length_over)));
}
http::send_file(channel_id.into().0, content, file, filename)
}
/// Sends a message to a [`Channel`].
///
/// Refer to the documentation for [`CreateMessage`] for more information
/// regarding message restrictions and requirements.
///
/// **Note**: Message contents must be under 2000 unicode code points.
///
/// # Example
///
/// Send a message with just the content `test`:
///
/// ```rust,ignore
/// // assuming you are in a context
/// let _ = context.send_message(message.channel_id, |f| f.content("test"));
/// ```
///
/// Send a message on `!ping` with a very descriptive [`Embed`]. This sends
/// a message content of `"Pong! Here's some info"`, with an embed with the
/// following attributes:
///
/// - Dark gold in colour;
/// - A description of `"Information about the message just posted"`;
/// - A title of `"Message Information"`;
/// - A URL of `"https://rust-lang.org"`;
/// - An [author structure] containing an icon and the user's name;
/// - An inline [field structure] containing the message's content with a
/// label;
/// - An inline field containing the channel's name with a label;
/// - A footer containing the current user's icon and name, saying that the
/// information was generated by them.
///
/// ```rust,no_run
/// use serenity::client::{STATE, Client, Context};
/// use serenity::model::{Channel, Message};
/// use serenity::utils::Colour;
/// use std::env;
///
/// let mut client = Client::login_bot(&env::var("DISCORD_TOKEN").unwrap());
/// client.with_framework(|f| f
/// .configure(|c| c.prefix("~"))
/// .on("ping", ping));
///
/// client.on_ready(|_context, ready| {
/// println!("{} is connected!", ready.user.name);
/// });
///
/// let _ = client.start();
///
/// fn ping(context: Context, message: Message, _arguments: Vec<String>) {
/// let state = STATE.lock().unwrap();
/// let ch = state.find_channel(message.channel_id);
/// let name = match ch {
/// Some(Channel::Public(ch)) => ch.name.clone(),
/// _ => "Unknown".to_owned(),
/// };
///
/// let _ = context.send_message(message.channel_id, |m| m
/// .content("Pong! Here's some info")
/// .embed(|e| e
/// .colour(Colour::dark_gold())
/// .description("Information about the message just posted")
/// .title("Message information")
/// .url("https://rust-lang.org")
/// .author(|mut a| {
/// a = a.name(&message.author.name);
///
/// if let Some(avatar) = message.author.avatar_url() {
/// a = a.icon_url(&avatar);
/// }
///
/// a
/// })
/// .field(|f| f
/// .inline(true)
/// .name("Message content:")
/// .value(&message.content))
/// .field(|f| f
/// .inline(true)
/// .name("Channel name:")
/// .value(&name))
/// .footer(|mut f| {
/// f = f.text(&format!("Generated by {}", state.user.name));
///
/// if let Some(avatar) = state.user.avatar_url() {
/// f = f.icon_url(&avatar);
/// }
///
/// f
/// })));
/// }
/// ```
///
/// Note that for most use cases, your embed layout will _not_ be this ugly.
/// This is an example of a very involved and conditional embed.
///
/// # Errors
///
/// Returns a [`ClientError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
/// [`Channel`]: ../model/enum.Channel.html
/// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong
/// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
/// [`Embed`]: ../model/struct.Embed.html
/// [author structure]: ../utils/builder/struct.CreateEmbedAuthor.html
/// [field structure]: ../utils/builder/struct.CreateEmbedField.html
pub fn send_message<C, F>(&self, channel_id: C, f: F) -> Result<Message>
where C: Into<ChannelId>, F: FnOnce(CreateMessage) -> CreateMessage {
let map = f(CreateMessage::default()).0;
if let Some(content) = map.get(&"content".to_owned()) {
if let Value::String(ref content) = *content {
if let Some(length_over) = Message::overflow_length(content) {
return Err(Error::Client(ClientError::MessageTooLong(length_over)));
}
}
}
http::send_message(channel_id.into().0, Value::Object(map))
}
pub fn set_game(&self, game: Option<Game>) {
self.connection.lock()
.unwrap()
.set_presence(game, OnlineStatus::Online, false);
}
/// Set the current game, passing in only its name. This will automatically
/// set the current user's [`OnlineStatus`] to [`Online`], and its
/// [`GameType`] as [`Playing`].
///
/// Pass `None` to remove the current user's current game.
///
/// [`GameType`]: ../model/enum.GameType.html
/// [`Online`]: ../model/enum.OnlineStatus.html#variant.Online
/// [`OnlineStatus`]: ../model/enum.OnlineStatus.html
/// [`Playing`]: ../model/enum.GameType.html#variant.Playing
pub fn set_game_name(&self, game: Option<&str>) {
self.connection.lock()
.unwrap()
.set_presence(game.map(|x| Game::playing(x.to_owned())),
OnlineStatus::Online,
false);
}
pub fn set_presence(&self,
game: Option<Game>,
status: OnlineStatus,
afk: bool) {
self.connection.lock()
.unwrap()
.set_presence(game, status, afk)
}
pub fn start_guild_prune<G>(&self, guild_id: G, days: u16)
-> Result<GuildPrune> where G: Into<GuildId> {
let map = ObjectBuilder::new()
.insert("days", days)
.build();
http::start_guild_prune(guild_id.into().0, map)
}
pub fn start_integration_sync<G, I>(&self, guild_id: G, integration_id: I)
-> Result<()> where G: Into<GuildId>, I: Into<IntegrationId> {
http::start_integration_sync(guild_id.into().0, integration_id.into().0)
}
/// Unbans a [`User`] from a [`Guild`].
///
/// Requires the [Ban Members] permission.
///
/// [`Guild`]: ../model/struct.Guild.html
/// [`User`]: ../model/struct.User.html
/// [Ban Members]: ../model/permissions/constant.BAN_MEMBERS.html
pub fn unban<G, U>(&self, guild_id: G, user_id: U) -> Result<()>
where G: Into<GuildId>, U: Into<UserId> {
http::remove_ban(guild_id.into().0, user_id.into().0)
}
pub fn unpin<C, M>(&self, channel_id: C, message_id: M) -> Result<()>
where C: Into<ChannelId>, M: Into<MessageId> {
http::unpin_message(channel_id.into().0, message_id.into().0)
}
}
|