c# - 计算用户在不和谐机器人语音通道中的时间
问题描述
似乎可以,但是当我退出语音通道时,时间仍然在数据库中计算。现在我将编辑问题并添加我的代码 _client.UserVoiceStateUpdated += UserConnection;
public static async Task UserConnection(SocketUser arg, SocketVoiceState stat1, SocketVoiceState stat2)
{
var user = arg as SocketGuildUser;
var profile = UsrDb.GetUserHours(user.Id, user.Guild.Id);
if (profile == null)
{
profile = new Usr
{
UserId = user.Id,
GuildId = user.Guild.Id
};
}
profile.startTime = DateTime.UtcNow;
await UsrDb.SetUsr(profile); //recording time in the database
}
[Command("check user time")]
public async Task UserTimeCheck()
{
var profile = UsrDb.GetUserHours(Context.User.Id, Context.Guild.Id);
var eb = new EmbedBuilder();
if (profile == null)
{
await ReplyAsync($"{Context.User.Username} your time 0 hours 0 minutes 0 second");
}
profile.endTime = DateTime.UtcNow;
TimeSpan total = profile.endTime - profile.startTime;
eb.WithAuthor($"{Context.User.Username} - Your voice time");
eb.WithDescription($"{total.Hours} hrs | {total.Minutes} min | {total.Seconds} sec.");
await ReplyAsync(embed: eb.Build());
}
解决方案
推荐阅读
- excel - 在ms excel中计算整行中连续值序列的数量
- excel - 如何使用来自不同列的值在 Excel 的 XY 散点图中添加不同的标记?
- typescript - 如何使用 Jest 和 TypeScript 正确存根/模拟 AWS SecretManager
- asp.net-mvc - 使用 Blazor 和实体框架时如何避免服务定位器模式?
- python - 停止无限循环的问题
- python - Django:为什么我的视频不会在模板中显示?(错误“找不到支持格式和 MIME 类型的视频”)
- .net - 我如何知道正在使用哪个版本的 .NET mono?
- vue.js - Webpack/Vue 未从根目录加载 runtime.js
- c++ - 从 MASM 将字符串推送到 C++
- python - Python 访问嵌套 JSON 数据并保存到数据框中