Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Checking a Role using Discord.NET and then Executing Code

Hello everyone! I'm trying to make my Discord Bot only be able to be used by the roles "admins", "owner" and "moderator"

Heres my code,
please help!


Code
commands.CreateCommand("clear")
            .Do(async (e) =>
            {
                
                var userPerms = e.User.Roles.ToString();
                if (userPerms == ("owner"))
                {
                    Message[] messagesToDelete;
                    messagesToDelete = await e.Channel.DownloadMessages(20);
                    await e.Channel.DeleteMessages(messagesToDelete);
                } else {
                    await e.Channel.SendMessage("`FederationBot had an Error! Are you an Admin?`");
                    await e.Channel.SendMessage("Error log is:\n"+ userPerms);
                    Console.WriteLine(userPerms);
                }
            });

Spoiler (Click to View)

If you need a Visual Aid to help ^
[Image: hf.png]

Rep for rep!
http://rtd.discord.foxbot.me/en/legacy/f...sions.html
Not familliar with Discord.NET but look at that link, should help you out.
(Mar 9, 2017 04:28 PM)caiveman Wrote:  Ur not a legitimate user
Ur a paki skid

(Mar 28, 2017 04:23 AM)goshmulticoloredalto Wrote:  http://rtd.discord.foxbot.me/en/legacy/f...sions.html
Not familliar with Discord.NET but look at that link, should help you out.

xD I tried this, still confused, because it mentions _channel* but it's never declared on what that actually is.

Any clue?


Obviously it's referring to the Channel but I dont know if its Discord.User.Channel or just Discord.Channel ;-;
[Image: hf.png]

Rep for rep!
You're using old api lib
You should use the Addchecker or minimum permission method instead of checking it in the command block, but if you want to do it that way this is how you do it in old version.

PHP Code

<?php 
var ownerRole = e.Server.FindRoles("owner").FirstOrDefault(); // find role

if (ownerRole == null) return; // role doesnt exists on the server

if(e.User.HasRole(ownerRole))
{
     
// user has the owner role
}
else
{
    
// user doesn't have the role
} 

FindRoles returns a IEnumerable<Role>
(Mar 28, 2017 10:11 AM).Monarch. Wrote:  You're using old api lib
You should use the Addchecker or minimum permission method instead of checking it in the command block, but if you want to do it that way this is how you do it in old version.

PHP Code

<?php 
var ownerRole = e.Server.FindRoles("owner").FirstOrDefault(); // find role

if (ownerRole == null) return; // role doesnt exists on the server

if(e.User.HasRole(ownerRole))
{
     
// user has the owner role
}
else
{
    
// user doesn't have the role
} 

FindRoles returns a IEnumerable<Role>

THANK YOU!!!!
[Image: hf.png]

Rep for rep!
Do you have a good tutorial on creating an auto-response bot? I've been starting to think of creating a bot for something, but getting lazy since I didn't find something easy to learn yet..
Have a cool signature? hit me up and I might use it.
(Mar 28, 2017 11:30 AM)severos Wrote:  Do you have a good tutorial on creating an auto-response bot? I've been starting to think of creating a bot for something, but getting lazy since I didn't find something easy to learn yet..

YouTube and Google is your friend, just look up "How to make a Discord Bot in C#" or something like that. It's easy once you get to know how some things work, and having an auto response bot like:
Code
!hai

BOT: hai
is easy as hell xD
[Image: hf.png]

Rep for rep!
(Mar 28, 2017 11:30 AM)severos Wrote:  Do you have a good tutorial on creating an auto-response bot? I've been starting to think of creating a bot for something, but getting lazy since I didn't find something easy to learn yet..

This is off-topic but i can help you with coding a bot, in node.js or C# doesnt matter.
(Mar 29, 2017 08:21 AM)Finn. Wrote:  This is off-topic but i can help you with coding a bot, in node.js or C# doesnt matter.

Nah I want it to be original,

thank ya tho
[Image: hf.png]

Rep for rep!


Possibly Related Threads...
Thread / Author Replies Views Last Post
by hanterokJun 26, 2023 01:04 PM 4 399 Jun 26, 2023 01:04 PM
Last Post: hanterok
[C#] by Memento_MoriJan 18, 2022 07:09 PM 2 262 Jan 18, 2022 07:09 PM
Last Post: DDDealer
[Python] by Killua.Nov 26, 2021 12:47 AM 3 185 Nov 26, 2021 12:47 AM
Last Post: nniks1999