【问题标题】:Restarting a command in Discord using c#使用 c# 在 Discord 中重新启动命令
【发布时间】:2017-10-28 18:03:51
【问题描述】:

所以我知道这看起来很愚蠢,但我尝试在我的机器人设定的时间间隔后重新启动一个方法。我把计时器和大部分代码一起调低了。但是,我无法在完成后重新启动该方法。我也尝试过使用 return;而不是调用重新启动,但这对我也不起作用。非常感谢任何帮助。

private void RegiseterAutoBleachCommand()
    {

        commands.CreateCommand("bleach")
            .Do(async (e) =>
            {
                Thread.Sleep(1000);
                int randomBleachIndex = rand.Next(bestBleach.Length);
                string bleachToPost = bestBleach[randomBleachIndex];
                await e.Channel.SendFile(bleachToPost);



                Restart();

            });
    }

    private void Restart()
    {
         RegiseterAutoBleachCommand();
    }

【问题讨论】:

    标签: c# c#-4.0 restart discord


    【解决方案1】:

    所以在寻找其他类似问题的答案之后。我跟着 while 命令来了,让它循环。

        private void RegiseterAutoBleachCommand()
    {
    
        commands.CreateCommand("bleach")
            .Do(async (e) =>
            {
    
                while (true)
               {
                Thread.Sleep(1000);
                int randomBleachIndex = rand.Next(bestBleach.Length);
                string bleachToPost = bestBleach[randomBleachIndex];
                await e.Channel.SendFile(bleachToPost);
    
                   }
    
            });
    }
    

    【讨论】:

      猜你喜欢
      • 2018-04-26
      • 2014-10-13
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 2017-06-04
      • 2018-05-01
      相关资源
      最近更新 更多