>我有一个计时器命令,您可以在其中输入所需的时间(以秒为单位(,然后等待。但是我想要它,以便在完成后标记您,但我不知道如何。
[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:");
}
将命令的运行模式设置为 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:");
}