小编Com*_*era的帖子

如何使用 DiscordSocketClient 获取用户的角色

我一直在锁定如何获取用户的角色以便我可以设置命令的权限。这是我的代码。我在较新版本中使用 Discord.NET。

using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AmberScript2.Modules
{
    public class Kick : ModuleBase<SocketCommandContext>
    {
        [Command("kick")]
        public async Task KickUser(string userName)
        {
            if (Context.Guild.GetRole(Context.Message.Author.Id).Name == "Administrator")
            {
                await Context.Channel.SendMessageAsync("Success!");
            }
            else
            {
                await Context.Channel.SendMessageAsync("Inadequate permisions.");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是未将对象引用设置为对象的实例。我一直试图找到它的来源,但我不能。谢谢。

(是的,我还没有摆脱多余的使用。这段代码还没有完成。)

.net c# roles discord discord.net

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

discord ×1

discord.net ×1

roles ×1