setOwner method

Future<void> setOwner(
  1. GuildMember guildMember
)

Update the owner of this

Warning : This method only works if the server was created via a discord bot and the bot is the current owner, see documentation.

final member = guild.members.cache.getOrFail('240561194958716924');
await guild.setOwner(member);

Implementation

Future<void> setOwner (GuildMember guildMember) async {
  if (owner != guildMember.guild.members.me) {
    ioc.use<ConsoleService>().error("You cannot change the owner of the server because it does not belong to the ${guildMember.guild.members.me.nickname} client.");
    return;
  }

  Response response = await ioc.use<DiscordApiHttpService>().patch(url: "/guilds/$id")
    .payload({ 'owner_id': guildMember.user.id })
    .build();

  if (response.statusCode == 200) {
    _ownerId = guildMember.id;
  }
}