我正在使用discord bot,我正在尝试检查时间服务的时间,但它只显示时间一次,然后写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();
}
并调用此函数
[Command("ping"), Summary("Echos a message.")]
public async Task Say()
{
// ReplyAsync is a method on ModuleBase
await ReplyAsync("PONG " + CommandHandler.time.ElapsedMilliseconds);
}
答案 0 :(得分:0)
尝试在异步功能中创建计时器。