I'm using discord bot, and I'm trying to check the time of the time service but its only shows the time only once and then writes 0
public async Task HandleCommand(SocketMessage messageParam)
{
// Don't process the command if it was a System Message
var message = messageParam as SocketUserMessage;
if (message == null || message.Author.IsBot)
return;
Console.WriteLine(message.Author);
time.Start();
// Create a number to track where the prefix ends and the command begins
int argPos = 0;
// Determine if the message is a command, based on if it starts with '!' or a mention prefix
if (!(message.HasCharPrefix('>', ref argPos)))
return;
// Create a Command Context
var context = new CommandContext(dbot, message);
Last = message.Author;
// Execute the command. (result does not indicate a return value,
// rather an object stating if the command executed successfully)
var result = await commands.ExecuteAsync(context, argPos, services);
time.Stop();
time.Reset();
}
and it calls this function
[Command("ping"), Summary("Echos a message.")]
public async Task Say()
{
// ReplyAsync is a method on ModuleBase
await ReplyAsync("PONG " + CommandHandler.time.ElapsedMilliseconds);
}
尝试在异步函数中创建计时器。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.