我一直在鎖定很長時間以獲取用戶的角色,因此我可以設置命令的權限。這是我的代碼。我在新版本中使用Discord.NET。如何通過DiscordSocketClient獲取用戶角色
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.");
}
}
}
}
我得到的錯誤是對象引用未設置爲對象的實例。我一直在試圖找到它的來源,我不能。謝謝。
(是的,我還沒有除掉多餘的usings的。此代碼還沒有完成。)
請在您的答案中嘗試添加一些示例代碼,詳細信息。 –