我正在处理一个不符合主持人的不和谐机器人,该机器人可以撤销功能的可用性(DICE卷(。我的目标是将其放在bool a = true; roll the dice
的位置。bool a = false; deny
。主持人将通过单独的函数更改布尔,他们可以更改A的布尔值并保持这种方式。
我尝试将布尔分配给单独的类并使用get和设置,但是该值是不立即更改或更改的。
[Command("diceRoll")]
[Summary("Turns on/off the ability to use the Dice Roll function")]
public async Task DiceRoll(string toggle)
{
switch (toggle)
{
case "on":
case "On":
case "ON":
diceToggle.DiceBool = true;
await Context.Channel.SendMessageAsync("Dice Roll Function: ON");
break;
case "off":
case "Off":
case "OFF":
diceToggle.DiceBool = false;
await Context.Channel.SendMessageAsync("Dice Roll Function: OFF");
break;
default:
await Context.Channel.SendMessageAsync("Dice Roll Function: ERROR");
break;
}
}
[Command("roll")]
[Summary("Dice Roll")]
public async Task Dice(int number)
{
if (diceToggle.DiceBool == true)
{
int randNumber = rand.Next(1, number);
if (randNumber == 8 || randNumber == 11 || randNumber == 18)
{ await Context.Channel.SendMessageAsync("You rolled an " + randNumber + "."); }
else
{ await Context.Channel.SendMessageAsync("You rolled a " + randNumber + "."); }
}
else if (diceToggle.DiceBool == false)
{
await Context.Channel.SendMessageAsync("This feature has been disabled.");
}
else
{
await Context.Channel.SendMessageAsync("Something broke, please fix.");
}
}
}
public class Game
{
private bool diceBool;
public bool DiceBool
{
get { return diceBool; }
set
{
if (diceBool != value)
{
diceBool = value;
}
}
}
}
我期望当" diceroll On/off"命令被称为"滚动"命令时,"滚动"命令将停止工作或再次工作。当前,该命令被调用,但布尔值没有更改或不变。
您无法"保存"该值的原因是模块在discord.net中的工作方式。与ASP.NET类似,模块是瞬态的,这意味着它们在执行后被内存销毁。请在此处查看完整的详细信息