我有一个计时器命令,您可以在几秒钟内输入您想要的时间,然后等待。但我想要它,所以当它完成它标记你但我不知道如何。
[Command("timer")]
[Summary("**%timer** + time in seconds and then it will tell you when it's done!")]
private async Task test(string input)
{
//something like this
User user = Context.User;
string name = Context.User.Username;
Int32 time = Convert.ToInt32(input);
time *= 1000;
await Context.Channel.SendMessageAsync(":stopwatch: **" + name + "** has put a timer on **" + input + "** seconds! :stopwatch:");
await Task.Delay(time);
//and then
await Context.Channel.SendMessageAsync(":stopwatch: **" + user + "'s** timer on **" + input + "** seconds is done! :stopwatch:");
}
答案 0 :(得分:1)
将命令的runmode设置为async:
[Command("timer", RunMode = RunMode.Async)] // <-- here
[Summary("**%timer** + time in seconds and then it will tell you when it's done!")]
private async Task test(string input)
{
Int32 time = Convert.ToInt32(input);
time *= 1000;
await Context.Channel.SendMessageAsync(":stopwatch: **" + Context.User.Mention + "** has put a timer on **" + input + "** seconds! :stopwatch:");
await Task.Delay(time);
await Context.Channel.SendMessageAsync(":stopwatch: **" + Context.User.Mention + "'s** timer on **" + input + "** seconds is done! :stopwatch:");
}