Amino-NET-Group / Amino.NET

An unofficial C# wrapper around Aminos REST API based on Amino.py!
MIT License
11 stars 2 forks source link

help #22

Closed Arata-SIN closed 7 months ago

Arata-SIN commented 7 months ago

I saved message.content in a variable text and i want to use text outside the function i have tried to access the the function the subclient but onmessage even just went mad giving me these errors

here is what i wanted to do first to make it easier on my self -->

static void Main(string[] args, Amino.Client client, Amino.SubClient ndcClient)
{

    client.onMessage += onMessageEvent;

    // Wait for user input to close the application
    Console.WriteLine("Press Enter to exit.");
    Console.ReadLine();

}

static void onMessageEvent(Amino.Objects.Message message,Amino.SubClient ndcClinent)
{
    var text = message.content;
    Console.WriteLine(message.content);

    if ( message.content == "hey")
{
    ndcClient.start_chat("907b17a7-5239-417f-9fd6-16cb309dbe32", "hey");
    ndcClient.send_message(chatId: message.chatId.ToString(), message: "heyhey");
}

}

Main(args, client,ndcClient);

Error

No overload for 'onMessageEvent' matches delegate 'Action<Message>' A static local function cannot contain a reference to 'this' or 'base'

here what im trying to do as a solution but i have a lack of knowledge in c

static void Main(string[] args, Amino.Client client, Amino.SubClient ndcClient)
{

    client.onMessage += onMessageEvent;

    // Wait for user input to close the application
    Console.WriteLine("Press Enter to exit.");
    Console.ReadLine();

}

static void onMessageEvent(Amino.Objects.Message message)
{
    var text = message.content;
    Console.WriteLine(message.content);

}

Main(args, client,ndcClient);

if ( text== "hey")
{
    ndcClient.start_chat("907b17a7-5239-417f-9fd6-16cb309dbe32", "hey");
    ndcClient.send_message(chatId: chatId.ToString(), message: "heyhey");
}
FabioGaming commented 7 months ago

Your issue is related to how you use the library, it is not a bug You need to login with your client to call on events first which you dont seem to do on this code