KickAsync Leads to HTTPException
See original GitHub issueHello,
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:
- Created 4 years ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
Thank you all for your prompt responses and help. You have a very intuitive and easy to use API.
Make sure the position of the role is higher - kicking/banning works on role position in the role list rather than permissions.