本文整理汇总了C#中Discord.DiscordClient.UsingPermissionLevels方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.UsingPermissionLevels方法的具体用法?C# DiscordClient.UsingPermissionLevels怎么用?C# DiscordClient.UsingPermissionLevels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.DiscordClient
的用法示例。
在下文中一共展示了DiscordClient.UsingPermissionLevels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start()
{
_client = new DiscordClient(x=> {
x.AppName = "CancerBot";
x.MessageCacheSize = 10;
x.EnablePreUpdateEvents = true;
});
_client.UsingPermissionLevels((u,c)=> (int)CheckPermLevel(u,c));
_client.UsingCommands(x => {
x.PrefixChar = '>';
x.HelpMode = HelpMode.Public;
x.ErrorHandler += HandleError;
x.AllowMentionPrefix = false;
});
var doc = new XmlDocument();
try
{
doc.Load("commands.xml");
}
catch (FileNotFoundException e)
{
StreamWriter stream = new StreamWriter("commands.xml");
XmlSerializer xml1 = new XmlSerializer(typeof(List<CustomCommand>));
xml1.Serialize(stream, new List<CustomCommand>());
stream.Close();
}
catch (XmlException e)
{
StreamWriter stream = new StreamWriter("commands.xml");
XmlSerializer xml1 = new XmlSerializer(typeof(List<CustomCommand>));
xml1.Serialize(stream, new List<CustomCommand>());
stream.Close();
}
CommandService commandService = _client.GetService<CommandService>();
List<CustomCommand> commands = new List<CustomCommand>();
XmlSerializer xml = new XmlSerializer(typeof(List<CustomCommand>));
FileStream file = new FileStream("commands.xml", FileMode.OpenOrCreate);
List<CustomCommand> list = (List<CustomCommand>)xml.Deserialize(file);
file.Close();
foreach(CustomCommand x in list)
{
if (forbodens.Contains<string>(x.Name)) { continue; }
CommandBuilder b = _client.GetService<CommandService>().CreateCommand(x.Name.ToLower()). Description(x.Contents).Parameter("Cuntents", ParameterType.Unparsed); b.Do(async e =>
{
double deltatime = 5;
if (LastCommandTime.ContainsKey(e.User.Id))
{
deltatime = (DateTime.Now.Second - LastCommandTime[e.User.Id]);
}
if (deltatime >= 5)
{
await e.Channel.SendMessage(x.Contents);
}
if (LastCommandTime.ContainsKey(e.User.Id))
{
LastCommandTime[e.User.Id] = DateTime.Now.Second;
}
else
{
LastCommandTime[e.User.Id] = DateTime.Now.Second;
}
});
try
{
b._command.IsCustom = true;
commandBuilders.Add(x.Name.ToLower(), b);
}
catch { Console.WriteLine($"Command with name {x.Name} already exists!"); };
}
_client.GetService<CommandService>().CreateCommand("test23").Description("Test Command").Do(async e =>
{
await e.Channel.SendMessage("test");
});
//_client.Ready += (s, e) =>
//{
// _client.FindServers("Discord Bots").First().FindChannels("testing-aloha").First().SendMessage("I'm alive!");
//};
commandService.CreateCommand("changename").Description("Changes Name").Parameter("Name", ParameterType.Unparsed).MinPermissions((int)PermissionLevel.ServerOwner)
.Do(async e =>
{
await _client.CurrentUser.Edit("", e.GetArg("Name"));
});
// _client.UserBanned += async (s, e) =>
// {
//await e.Server.DefaultChannel.SendMessage(e.User.Name + " was banned forever LUUL");
//};
//.........这里部分代码省略.........