So I am having some trouble referencing a dictionary. I am trying to make an economy discord bot. I want the user to setup the dictionary with the command !g setup, then type !g register to register their Discord ID to the dictionary.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Discord.Commands;
using Discord;
namespace Games_Bot.Modules
{
public class Commands : ModuleBase<SocketCommandContext>
{
public Dictionary<ulong, int> economy;
[Command("g setup")]
public async Task Setup()
{
economy = new Dictionary<ulong, int>();
}
[Command("g register")]
public async Task Register()
{
var userInfo = Context.User;
try
{
if (economy.ContainsKey(userInfo.Id) == false) { economy.Add(userInfo.Id, 0); }
}
catch { return; }
}
}
}
Whenever I try to reference the dictionary in Register(), Visual Studio throws me a null error. Any help is appreciated!