当前位置: 首页>>代码示例>>C#>>正文


C# DiscordClient.UsingCommands方法代码示例

本文整理汇总了C#中Discord.DiscordClient.UsingCommands方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.UsingCommands方法的具体用法?C# DiscordClient.UsingCommands怎么用?C# DiscordClient.UsingCommands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Discord.DiscordClient的用法示例。


在下文中一共展示了DiscordClient.UsingCommands方法的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");
            //};
//.........这里部分代码省略.........
开发者ID:thedanieldude1,项目名称:DanielCode,代码行数:101,代码来源:Program.cs


注:本文中的Discord.DiscordClient.UsingCommands方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。