Discord.Net - Check if User has ManageServer permission - c#

Trying to check if a User has the ManageServer Permission. I've already got the DiscordClientId & DiscordGuildId and the below is designed to get the current users permissions and from there I can specify the permission I'm looking for, but I can't figure it out
var user = userClientId;
var server = guildId;
var userServerPermissions = server.GetPermissions(user);
EDIT: I'm using a HttpWebRequest to get the DiscordClientId and GuildId's for the user when they login via Oauth2, then splitting out the various data I need to get the Id's.

I strongly recommend that you look into using a library for doing this. The one I've always used is Discord.NET, the library you mentioned on your question with the discord.net tag. Another C# discord library I'm aware of is DSharpPlus but I've never tried it.
For Discord.NET I suggest using the nightly/preview versions because they incorporate the recent Discord intents change. Use them by adding https://www.myget.org/F/discord-net/api/v3/index.json to your Nuget package sources.
A library handles everything nicely for you, meaning that you never need to directly send requests to or receive requests from Discord. Read the Discord.NET getting started guide here.
Here's code from Discord.NET which will determine if some user in some guild has the ManageServer permission:
public bool HasManageServerPermission(SocketGuildUser user)
{
return user.GuildPermissions.ManageGuild;
}

Related

Is it possible to code a clientsided Discord Bot, answering to Dms?

I am trying to create a client-side Discord Bot that can read my private messages and respond to them automatically. For example, if someone sends me the message "ping" in my DMs, the bot would reply with "pong". I am looking to create this bot using C#, but I am not sure where to start or if there are any specific tools or libraries that would be helpful for this task.
I have done some research and found a lot of information on how to create Discord Bots using Python, but most of it relates to creating server-side bots, not client-side ones like I am looking to do.
I am having difficulty finding information specifically on how to create a client-side Discord Bot that can read private messages and respond to them automatically. Any guidance or advice on how to accomplish this would be greatly appreciated.
You can do it using discord.py library for python. Just create simple event listener and send DM to a user with given ID like this:
import discord
intents = discord.Intents.default()
intents.members = True
client = discord.Client()
#client.event
async def on_message(message):
if message.content == "help me":
user = client.get(YOUR_ID) # specify your Discord account ID here
if user is not None:
await user.send("Hi someone needs help")
client.run("TOKEN")

Is there a way to get current Google Authenticator 2FA key for a specific account (client-side)

I am searching for a way to obtain the current code in my Google Authenticator app. for a specific account.
Please note that I'm not looking for embedding Google 2FA to any of server-side application - I guess it has been already well-documented.
I am trying to get the same current code shown in my own Google 2FA app. (by providing my Google credientials ofcourse) so I can make my app fully automated even when logging in (to a specific system/website) without asking for the code each time I start the app.
Thanks by now.
UPDATE:
Even if I can't find any answer or simply "there is no way", there is still a way even if it's too ugly.
Running an ios/android simulator (and configure it once by installing the Google Auth app) and simulate the mouse clicks over it and then capturing a screenshot and decoding the code from the image would be much of a work but also can actually work. I'm just trying to find a better way, if there is any.
You could solve this by generating the OTP code locally using a library such as OTP.Net. Simply save the secret locally, and add it to .gitignore if using git.
Then you can make a code on demand like so:
using OtpNet;
var totp = new Totp(secretKey);
var totpCode = totp.ComputeTotp();

My Question C# Setting a Status to User (Online/Idle) Discord.NET 1.0.2

I want to set a status to discord account. It connected to token.
My problem is on visual studio.
I tried to set SetGameAsync, and it worked. But when i tried to set a status like "Idle" or "Online" of User account, Its not working. How can i set status of a person?
I tried to 2 codes. There are:
Client.CurrentUser.Status(UserStatus.Idle);,
Client.SetStatusAsync(UserStatus.Idle);
I know there is no set option for SetStatusAsync. But there is no set option for SetGameAsync too. But it can.
Setting Status for Client
See the official documentation on the method SetStatusAsync, where it is said that the method belongs to the class DiscordSocketClient, meaning in your context, you should be doing client.SetStatusAsync.
Self-botting
Additionally, Discord.NET itself does not condone the use of "self-botting" as described in its FAQ, hence the obsoleting of TokenType.User in Discord.NET 2.0+. By forcing your account into using the API, you are risking your account of getting banned by Discord. Because of this, Discord.NET developers are not responsible for any actions or unexpected behaviors caused by this.

Discord.NET assigning roles

I am trying to get my discord bot to assign a role to a user when they input the command '!stream' I am very new to programming in c# and discord.net especially. Right now I have the code that should be assigning the role inside of a message received method. This probably isn't the best way to do it but I'm not super sure a better way right now. Anyways, here is the code:
IGuildUser user = (IGuildUser)arg.Author;
IRole role = ((IGuildChannel)arg.Channel).Guild.GetRole(theRoleID);
if (arg.Content == "!stream") {
await (user as IGuildUser).AddRoleAsync(role);
}
I have made sure both user, and role is getting the correct user and correct role. Its also running the if statement because I had output inside of it. The only thing that doesn't seem to be working is the actual assignment. Any help is greatly appreciated. Thanks!
If everything on the code side is already working, you might have a permissions issue on the Discord server itself.
I'll explain with an example:
Something similar happened to me a while back when trying to make some moderation commands that didn't work for the life of me, even though the code was correct and it gave no errors.
The issue turned out to be the role hierarchy on the discord server: basically the role the bot has assigned can only affect those underneath him, take for example the screenshot:
You'll notice there's an Inquisition role right underneath the Admin one.
That's a bot, which needs to be on top of every other role to be able to interact with those users, so I suggest you try and move your bot up the role ladder and see if that fixes your issue.
Hey Solonce your way of adding a role is almost correct but instead of your way of doing this using the ifs use the already added way to add new commands to your bot. I assume ! is your prefix and the stream is the command/word you want the bot to read and add the role accordingly. Let me know if your case is not what I assume.
So here is how it should ideally be done.
Create a public class and make it inherit from ModuleBase<SocketCommandContext> so it looks like public class Matches : ModuleBase<SocketCommandContext>.
Once you are done you can use [Command("stream")] to setup any commands you want for the bot.
And the way to add the roles is somewhat like this
[Command("stream")]
public async Task RoleTask()
{
ulong roleId = 486599202093269012;
var role = Context.Guild.GetRole(roleId);
await ((SocketGuildUser) Context.User).AddRoleAsync(role);
}
On this the bot (if it has enough permissions) should grant the role with the roleId to the user who sends the command. ie !stream
Also you know if you are going to get started I'd really suggest you to have a look at some great documentation at http://docs.stillu.cc and another good way is to look at examples in order to learn.
This is the bot I made way way back when I was getting started. Maybe you could learn.

How can I change Skype user status from online to away using skype4com?

How can I change my Skype status (from online to away, offline) using skype4com dll? I am working in C#. Answers that provide sample code would be most helpful to me.
Once you have attached to skype you just need to call ChangeUserStatus method:
var skype = new Skype();
skype.Attach(5, true);
skype.ChangeUserStatus(TUserStatus.cusAway);
I believe you can use the GET USERSTATUS command via the Skype Public API ("Skype Accessories"), which enables you to get or set the user's status.
The API reference documentation is here.

Categories

Resources