不和谐服务器的每日金钱系统无法正常工作
Daily money system for discord server not working properly
我正在尝试使用 Discord 机器人和 discord.Net api 包装器实现每日支付系统(假服务器货币)。我的代码似乎确实可以正确更新该余额并识别日期更改,但它似乎不记得谁收取了他们的每日付款。请帮忙。谢谢
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AmberScript3.Modules
{
public class DailyMoney : ModuleBase<SocketCommandContext>
{
List<string> users = new List<string>();
string currentDate = DateTime.Now.ToString("yyyyMMdd");
[Command("money daily")]
public async Task DailyCash()
{
string author = Context.Message.Author.Username;
if(DateTime.Now.ToString("yyyyMMdd") != currentDate)
{
users.Clear();
}
if(users.Contains(author))
{
await Context.Channel.SendMessageAsync("You have already reclaimed your daily payment!");
}
else
{
users.Add(author);
Random r = new Random();
int seed = r.Next(1000);
double val = Math.Round(r.NextDouble() * seed, 2);
Money.AddBalance(Context.Message.Author.Username, val);
await Context.Channel.SendMessageAsync($"Added ${val} to {author}'s account as a daily payment.");
}
currentDate = DateTime.Now.ToString("yyyyMMdd");
}
}
}`
DailyMoney class 是抽象的,因此它的每个实例化版本都有不同的值。我会将您想在实例化之间保留的内容存储在本地文本文件中,然后在创建时将它们抓取到代码中。如果你真的想要,你可以将所有这些值保存在一个单独的 class 中,并使用 Newtonsoft.Json 的 JsonConvert.SerializeObject
和 JsonConvert.DeserializeObject
来存储它。网上有很多关于这些东西的文档。虽然,只是为了一个字符串列表,只是将它存储在一个文本文件中。
我正在尝试使用 Discord 机器人和 discord.Net api 包装器实现每日支付系统(假服务器货币)。我的代码似乎确实可以正确更新该余额并识别日期更改,但它似乎不记得谁收取了他们的每日付款。请帮忙。谢谢
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AmberScript3.Modules
{
public class DailyMoney : ModuleBase<SocketCommandContext>
{
List<string> users = new List<string>();
string currentDate = DateTime.Now.ToString("yyyyMMdd");
[Command("money daily")]
public async Task DailyCash()
{
string author = Context.Message.Author.Username;
if(DateTime.Now.ToString("yyyyMMdd") != currentDate)
{
users.Clear();
}
if(users.Contains(author))
{
await Context.Channel.SendMessageAsync("You have already reclaimed your daily payment!");
}
else
{
users.Add(author);
Random r = new Random();
int seed = r.Next(1000);
double val = Math.Round(r.NextDouble() * seed, 2);
Money.AddBalance(Context.Message.Author.Username, val);
await Context.Channel.SendMessageAsync($"Added ${val} to {author}'s account as a daily payment.");
}
currentDate = DateTime.Now.ToString("yyyyMMdd");
}
}
}`
DailyMoney class 是抽象的,因此它的每个实例化版本都有不同的值。我会将您想在实例化之间保留的内容存储在本地文本文件中,然后在创建时将它们抓取到代码中。如果你真的想要,你可以将所有这些值保存在一个单独的 class 中,并使用 Newtonsoft.Json 的 JsonConvert.SerializeObject
和 JsonConvert.DeserializeObject
来存储它。网上有很多关于这些东西的文档。虽然,只是为了一个字符串列表,只是将它存储在一个文本文件中。