question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KickAsync Leads to HTTPException

See original GitHub issue

Hello,

I send this function KickUser the user I want kicked, the user doing the kicking, and the reason, if any.

[RequireBotPermission(GuildPermission.KickMembers)]
private async Task KickUser(IGuildUser user, SocketGuildUser personKicking, string reason = null)
{
    // user is the person being kicked.
    var textChannel = this._client.GetChannel(this._channelId) as SocketTextChannel;
    if (user == null) await textChannel.SendMessageAsync($"User doesn't exist. " +
        $"Cannot kick this user.");
    var role = user.Guild.Roles.FirstOrDefault(x => x.Name == "Admin");

    await textChannel.SendMessageAsync($"Attempting to kick {user.Mention}. " +
        $"Reason: {reason ?? "Admin has his reasons."}");

    if (!(user as SocketGuildUser).Roles.Contains(role))
    {
        if (personKicking.GuildPermissions.KickMembers)
        {
            await user.KickAsync(reason); // ERROR
        }
        else
        {
            await textChannel.SendMessageAsync($"You don't have permissions" +
                $" to kick {user.Mention}");
        }
    }
    else
    {
        await textChannel.SendMessageAsync($"{user.Mention} is an Admin." +
            $" They cannot be kicked.");
    }
}

Everytime it hits the “KickAsync” line, it throws an the following exception: Exception thrown: 'Discord.Net.HttpException' in System.Private.CoreLib.dll

Why is this happening? How can I resolve it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Tzadikocommented, Feb 7, 2020

Aaahhh that’s how roles work! Haha, okay, I’m new to Discord and I skipped over the caption on the Role Linear Hierachy picture here: https://support.discordapp.com/hc/en-us/articles/214836687-Role-Management-101

The blurple arrow is your highest role; roles now follow a linear hierarchy. In simpler terms, the “metaphorical totem pole” is now a bit more literal in practice.

Thank you all for your prompt responses and help. You have a very intuitive and easy to use API.

image

0reactions
FiniteRealitycommented, Feb 7, 2020

Make sure the position of the role is higher - kicking/banning works on role position in the role list rather than permissions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interface IGuildUser
This property returns a read-only collection of the identifiers of the roles that this user possesses. For WebSocket users, a Roles property can...
Read more >
Exception cant be casted to HttpException
Anyone can explain what can be reasons to when i throw a HttpException, when its bubbled up, cant be casted from Exception.
Read more >
Discord.Net
MoveNextAsync() ), an HttpException is thrown with the message "Missing Access". This is probably due to the fact that there is no DIRECT_MESSAGES...
Read more >
C# (CSharp) SocketGuildUser Examples
public async Task Kick([Remainder] SocketGuildUser user) { await ReplyAsync($"cya ... Variable is declared but never used catch (HttpException e) { Logger.
Read more >
C# (CSharp) IGuildUser Examples
C# (CSharp) IGuildUser - 60 examples found. These are the top rated real world C# (CSharp) examples of IGuildUser extracted from open source...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found