如何在不和谐中制作动态机器人命令?

时间:2016-12-13 21:51:05

标签: c# discord discord.net

所以我通常使用以下代码行创建一个新的bot命令:

private void SayHi()
{
    commands.CreateCommand("sayhi").Do(async (e) => {
            await e.Channel.SendMessage("Hi");
    });
}

然后,频道中的用户可以输入"!sayhi",然后打印出"Hi"。我在discord.net中使用C#包尝试做的是创建一个动态命令。这样用户就可以输入如下内容:!sayhi x其中x是用户选择使用的任何字符串。我希望能够输出如下内容:

commands.CreateCommand("sayhi" + x).Do(async (e) => {
        await e.Channel.SendMessage("Hi" + x);
});

将不和谐的输出看作:"Hi x"

1 个答案:

答案 0 :(得分:3)

基于文档。您将使用参数方法

http://rtd.discord.foxbot.me/en/legacy/features/commands.html#example-simple

<div class="row">
  <div class="svart active">
    <img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/9ec68cc6081481151513.png" />
    <p>
      1 key
    </p>
  </div>
  <div class="svart">
    <img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/9ec68cc6081481151513.png" />
    <p>
      1 key
    </p>
  </div>
</div>
<!-- !.row -->
<div class="row">
  <div class="svart active">
    <img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/9ec68cc6081481151513.png" />
    <p>
      1 key
    </p>
  </div>
  <div class="svart">
    <img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/9ec68cc6081481151513.png" />
    <p>
      1 key
    </p>
  </div>
  <div class="svart">
    <img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/9ec68cc6081481151513.png" />
    <p>
      1 key
    </p>
  </div>
  <div class="svart">
    <img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/9ec68cc6081481151513.png" />
    <p>
      1 key
    </p>
  </div>
  <div class="svart">
    <img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/9ec68cc6081481151513.png" />
    <p>
      1 key
    </p>
  </div>
  <div class="svart">
    <img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/9ec68cc6081481151513.png" />
    <p>
      1 key
    </p>
  </div>
  <div class="svart">
    <img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/9ec68cc6081481151513.png" />
    <p>
      1 key
    </p>
  </div>
</div>
<!-- !.row -->
<!--
<div class="svart"><img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/9ec68cc6081481151513.png">
  <p>1 key</p>
</div>

<div class="svart"><img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/e3a37efb651475612008.png">
  <p>7 cases // 1 key</p>
</div>

<div class="svart"><img class="inni" src="https://rocket-league.com//content/media/items/avatar/220px/2aa4fb89721474239225.png">
  <p>3 cases // 1 key</p>
</div>

<p>
  <div class="svart"><img class="inni" src="https://rocket-league.com//content/media/items/avatar/220px/5975237f541474239197.png">
    <p>7 cases // 1 key</p>
  </div>

  <div class="imgWrap">
    <div class="svart"><img class="inni" src="https://rocket-league.com//content/media/items/avatar/220px/75e8bb7e5d1473412157.png">
      <p>2 keys</p>
    </div>
  </div>

  <div class="imgWrap">
    <div class="svart"><img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/8d04eb69ff1473412255.png">
      <p>1 key</p>
    </div>
  </div>

  <div class="imgWrap">
    <div class="svart"><img class="inni" src="https://rocket-league.com//content/media/items/avatar/220px/7bd39778fe1473412354.png">
      <p>1 key</p>
    </div>
  </div>

  <div class="imgWrap">
    <div class="svart"><img class="inni" src="https://rocket-league.com//content/media/items/avatar/220px/fa26b845f91473412371.png">
      <p>1 key</div>
  </div>

  <div class="imgWrap">
    <div class="svart"><img class="inni" src="https://rocket-league.com//content/media/items/avatar/220px/97eb34e7631475683880.png">
      <p>1-2 keys</p>
    </div>
  </div>

  <div class="imgWrap">
    <div class="svart"><img class="inni" src="https://rocket-league.com/content/media/items/avatar/220px/6db50395201481302229.png">
      <p>7-8 keys</p>
    </div>
  </div>
  -->