I'm trying to have the bot have some dictionary features and so I'm using FreeDictionaryAPI to do this.
public class DictionaryCommand : BaseCommandModule
{
[Command("dict")]
public async Task dictCommand(CommandContext ctx)
{
//await ctx.Channel.SendMessageAsync("Penis");
var dictionary = new DictionaryOutput();
Console.WriteLine(ctx.Message.Content.Remove(0, 5));
Console.WriteLine(ctx.Message.Content);
await dictionary.getDefinition(ctx.Message.Content.Remove(0, 5));
Console.WriteLine(dictionary.defo);
await ctx.Channel.SendMessageAsync(dictionary.defo);
}
}
should in theory run
public string defo { get; set; }
public async Task getDefinition(string message)
{
//Dictionary stuff
string DictionaryURL = "https://api.dictionaryapi.dev/api/v2/entries/en/" + message;
Console.WriteLine(DictionaryURL);
using (var client = new HttpClient())
{
try
{
var response = await client.GetStringAsync(DictionaryURL);
List<Word>? word = JsonSerializer.Deserialize<List<Word>>(response.ToString());
defo = word[0].meanings[0].definitions[0].definition;
Console.WriteLine(defo);
}
catch (HttpRequestException exception)
{
Console.WriteLine("Error: {0}", exception);
}
}
}
But this does not happen. Also, if I write the command with a space (.dict hello), the entire program just ceases to work.