我一直在锁定如何获取用户的角色以便我可以设置命令的权限。这是我的代码。我在较新版本中使用 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)
我得到的错误是未将对象引用设置为对象的实例。我一直试图找到它的来源,但我不能。谢谢。
(是的,我还没有摆脱多余的使用。这段代码还没有完成。)