setIcon method
Modifies the icon of the role from String path.
We consider having the file structure
.dart_tool
assets/
images/
penguin.png
src/
test/
.env
pubspec.yaml
Example :
final Role? role = guild.roles.cache.get('240561194958716924');
if (role != null) {
await role.setIcon('assets/images/penguin.png');
}
Implementation
Future<void> setIcon (String path) async {
if (!manager.guild.features.contains(GuildFeature.roleIcons)) {
throw MissingFeatureException(cause: "Guild ${manager.guild.name} has no 'ROLE_ICONS' feature.");
}
String icon = await Helper.getPicture(path);
Http http = ioc.singleton(Service.http);
Response response = await http.patch(url: "/guilds/${manager.guild.id}/roles/$id", payload: { 'icon': icon });
if (response.statusCode == 200) {
_icon = icon;
}
}