add method
Add a Role to the GuildMember
Example :
final Role? role = guild.roles.cache.get('446556480850755604');
final GuildMember? member = guild.members.cache.get('240561194958716924');
if (member != null && role != null) {
await member.roles.add(role.id)
}
You can pass a reason for the audit logs.
Example :
await member.roles.add('446556480850755604', reason: 'I love this user');
Implementation
Future<void> add (Snowflake id, {String? reason}) async { Role? role = manager.cache.get(id);
if(role == null) {
throw NotExistException('You can\'t add a role that don\'t exist!');
}
Map<String, String> headers = {};
if(reason != null) {
headers.putIfAbsent('X-Audit-Log-Reason', () => reason);
}
Response response = await ioc.use<HttpService>().put(
url: '/guilds/${manager.guild.id}/members/$memberId/roles/$id',
payload: {},
headers: headers
);
if(response.statusCode == 204) {
cache.putIfAbsent(id, () => role);
}
}