IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

System NullReferenceException (bot Discord)


Sujet :

C#

  1. #1
    Membre habitué Avatar de Hamza
    Homme Profil pro
    Data Analyst
    Inscrit en
    Avril 2005
    Messages
    295
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Algérie

    Informations professionnelles :
    Activité : Data Analyst
    Secteur : Distribution

    Informations forums :
    Inscription : Avril 2005
    Messages : 295
    Points : 164
    Points
    164
    Par défaut System NullReferenceException (bot Discord)
    Bonjour,

    ci-dessous un bou de code permettant d'assigner les roles pour chaque utilisateur clique sur le bouton correspondant a sa classe

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    var inter = ctx.Client.GetInteractivity();
     
                var result = await inter.WaitForReactionAsync(
                    x => x.Message == joinmsg && x.User == ctx.User && (x.Emoji == tank || x.Emoji == heal)).ConfigureAwait(false);
     
                if (result.Result.Emoji == tank)
                {
                    var TankR = ctx.Guild.GetRole(1041428679978401913);
                    await ctx.Member.GrantRoleAsync(TankR).ConfigureAwait(false);
                }else if (result.Result.Emoji == heal)
                {
                    var HealR = ctx.Guild.GetRole(1043891142560862291);
                    await ctx.Member.GrantRoleAsync(HealR).ConfigureAwait(false);
                }
    le problème est qu'à chaque fois que je clique sur un bouton j'ai le message d'erreur ci-dessous
    Nom : error.PNG
Affichages : 471
Taille : 43,5 Ko

    j'avoue que je suis perdu.

  2. #2
    Membre chevronné
    Avatar de PixelJuice
    Homme Profil pro
    Ingénieur .NET & Game Designer
    Inscrit en
    Janvier 2014
    Messages
    639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Ingénieur .NET & Game Designer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 639
    Points : 2 148
    Points
    2 148
    Par défaut
    Bonsoir,

    Alors je ne suis pas familier avec DSharpPlus (plutôt avec Discord.net), mais je vais essayer quand même.

    Peux-tu dire quelle est la variable qui est nulle ? Je partirais du principe que c'est Guild vu que si c'était ctx ça n'arriverait pas jusque là. Et j'imagine aussi que GetRole() renvoie null au lieu d'une exception, mais autant être sûr.

    Du coup, s'agit-il d'un contexte de Guilde ? L'ID du rôle est-il le bon ? Je pense que oui mais vaut mieux en être sûr.

    Mise à part ces quelques maigres pistes, je ne vois pas ce que pourrait être le problème.

  3. #3
    Membre habitué Avatar de Hamza
    Homme Profil pro
    Data Analyst
    Inscrit en
    Avril 2005
    Messages
    295
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Algérie

    Informations professionnelles :
    Activité : Data Analyst
    Secteur : Distribution

    Informations forums :
    Inscription : Avril 2005
    Messages : 295
    Points : 164
    Points
    164
    Par défaut
    Bonjour,

    L'ID du Rôle est bonne. ce pendant Guild es vide, du coup la variable tankR est vide, je ne suis pas très familier avec l'outil du compilateur mais voilà ce que j'ai
    Nom : error bot2.png
Affichages : 418
Taille : 13,4 Ko

    pour plus de détail

    Nom : error bot.png
Affichages : 425
Taille : 236,5 Ko

    j'ai même tester avec la ligne de code ci-dessous, sa renvoie la même erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    var TankR = ctx.Guild.EveryoneRole;

  4. #4
    Membre chevronné
    Avatar de PixelJuice
    Homme Profil pro
    Ingénieur .NET & Game Designer
    Inscrit en
    Janvier 2014
    Messages
    639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Ingénieur .NET & Game Designer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 639
    Points : 2 148
    Points
    2 148
    Par défaut
    Du coup, pour avoir eu le même problème en mettant à jour mon propre bot, regarde du côté des options de ton Application liée au Bot, sur le site de l'API Discord.

    Il y a eu des mise à jour niveau droits (les intents) et il faut préciser si le bot a le droit ou non d'aller chercher certaines informations. Il ne s'agit que de cases à cocher sur leur site et de droits à préciser dans le bot (si jamais ce n'est pas le cas) et ça devrait marcher normalement.

  5. #5
    Membre habitué Avatar de Hamza
    Homme Profil pro
    Data Analyst
    Inscrit en
    Avril 2005
    Messages
    295
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Algérie

    Informations professionnelles :
    Activité : Data Analyst
    Secteur : Distribution

    Informations forums :
    Inscription : Avril 2005
    Messages : 295
    Points : 164
    Points
    164
    Par défaut
    Bonsoir et merci de ton aide,

    pour les case à cocher voilà ce que j'ai
    Nom : error bot 3.png
Affichages : 423
Taille : 80,8 Ko

    quand je coche les case Guilds,guilds.join et Guilds.members.read
    il me demande de saisir redirect URL. Suite a une petite recherche j'ai trouvé qu'il saisir cette adresse
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    https://discordapp.com/oauth2/authorize?&client_id=[CLIENTID]&scope=bot
    et remplacer ID CLIENT par mon ID voir la source ici

    et quand je tente d'ajouter le bot dans le serveur cela me dit que ID client n'est pas une valeur snowflake, le bot est bien ajouter dans le serveur mais quand je teste la commande je me retrouve toujours dans le même problème.

  6. #6
    Membre chevronné
    Avatar de PixelJuice
    Homme Profil pro
    Ingénieur .NET & Game Designer
    Inscrit en
    Janvier 2014
    Messages
    639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Ingénieur .NET & Game Designer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 639
    Points : 2 148
    Points
    2 148
    Par défaut
    Il te suffit de cocher les cases suivantes uniquement



    Et si ça ne marche toujours pas, il faut mettre ceci dans la création de DiscordConfiguration, qui comme son nom l'indique, te sert de config pour le bot.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    var config = new DiscordConfiguration()
    {
        Intents = DiscordIntents.All
    };
    Voilà, si c'était pour le coup ça qui te posait ton problème, n'hésite pas a mettre des intents plus spécifiques.

  7. #7
    Membre habitué Avatar de Hamza
    Homme Profil pro
    Data Analyst
    Inscrit en
    Avril 2005
    Messages
    295
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Algérie

    Informations professionnelles :
    Activité : Data Analyst
    Secteur : Distribution

    Informations forums :
    Inscription : Avril 2005
    Messages : 295
    Points : 164
    Points
    164
    Par défaut
    Bonjour,

    Tout cela est déjà fait, après quand tu dis :
    n'hésite pas a mettre des intents plus spécifiques.
    quand on met
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Intents = DiscordIntents.All,
    cela attribuera tous les droits non ?

  8. #8
    Membre chevronné
    Avatar de PixelJuice
    Homme Profil pro
    Ingénieur .NET & Game Designer
    Inscrit en
    Janvier 2014
    Messages
    639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Ingénieur .NET & Game Designer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 639
    Points : 2 148
    Points
    2 148
    Par défaut
    Bonsoir,

    Oui en effet ça mets tout les droits, mais si ça aurait marcher, il aurait été + judicieux de ne pas tout mettre et cibler.

    Je pensais que ça règlerai ton problème mais apparemment non, pourtant c'était une bonne piste.

    Essaye de voir si tu arrives a récupérer la guilde avec d'autres actions, etc ... afin d'en trouver une meilleure.

  9. #9
    Membre habitué Avatar de Hamza
    Homme Profil pro
    Data Analyst
    Inscrit en
    Avril 2005
    Messages
    295
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Algérie

    Informations professionnelles :
    Activité : Data Analyst
    Secteur : Distribution

    Informations forums :
    Inscription : Avril 2005
    Messages : 295
    Points : 164
    Points
    164
    Par défaut
    Bonsoir,

    est-ce que sa un rapport avec ce msg d'erreur dans la console ? le websocket
    Nom : error 2.PNG
Affichages : 429
Taille : 37,7 Ko

  10. #10
    Membre expérimenté
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 116
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 116
    Points : 1 622
    Points
    1 622
    Par défaut
    il faudrait voir, selon moi, le reste du message d'erreur qui est en dessous, et qui semble indiqué un problème d'authentification (ce qui a pu fermé le socket pour le coup)

  11. #11
    Membre habitué Avatar de Hamza
    Homme Profil pro
    Data Analyst
    Inscrit en
    Avril 2005
    Messages
    295
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Algérie

    Informations professionnelles :
    Activité : Data Analyst
    Secteur : Distribution

    Informations forums :
    Inscription : Avril 2005
    Messages : 295
    Points : 164
    Points
    164
    Par défaut
    le message au complet, dsl je débute dans ce genre de chose
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    [2022-11-24 14:27:58 +01:00] [108 /WebSocketRec] [Error] Socket handler suppressed an exception
    Newtonsoft.Json.JsonSerializationException: Error setting value to 'OAuthFlags' on 'DSharpPlus.Entities.DiscordMember'.
     ---> System.NullReferenceException: Object reference not set to an instance of an object.
       at DSharpPlus.Entities.DiscordMember.get_User()
       at DSharpPlus.Entities.DiscordMember.set_OAuthFlags(Nullable`1 value)
       at lambda_method(Closure , Object , Object )
       at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
       --- End of inner exception stack trace ---
       at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
       at Newtonsoft.Json.Serialization.JsonSerializerProxy.DeserializeInternal(JsonReader reader, Type objectType)
       at DSharpPlus.Net.Serialization.SnowflakeArrayAsDictionaryJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
       at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
       at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
       at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
       at Newtonsoft.Json.Linq.JToken.ToObject[T](JsonSerializer jsonSerializer)
       at DSharpPlus.Net.Serialization.DiscordJson.ToDiscordObject[T](JToken token)
       at DSharpPlus.DiscordClient.HandleDispatchAsync(GatewayPayload payload)
       at DSharpPlus.DiscordClient.HandleSocketMessageAsync(String data)
       at DSharpPlus.DiscordClient.<InternalConnectAsync>g__SocketOnMessage|478_1(IWebSocketClient sender, SocketMessageEventArgs e)

  12. #12
    Membre expérimenté
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 116
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 116
    Points : 1 622
    Points
    1 622
    Par défaut
    Le bug est signalé sur le github de DSharpPlus https://github.com/DSharpPlus/DSharp...scordMember%27.
    La solution est d'utiliser une version >= 4.2.0-nightly.01104 (cocher la case "inclure la version préliminaire" dans le gestionnaire NuGet) (DSharpPlus 4.2.0 stable devrait inclure la correction je pense, car sortie après)

  13. #13
    Membre habitué Avatar de Hamza
    Homme Profil pro
    Data Analyst
    Inscrit en
    Avril 2005
    Messages
    295
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Algérie

    Informations professionnelles :
    Activité : Data Analyst
    Secteur : Distribution

    Informations forums :
    Inscription : Avril 2005
    Messages : 295
    Points : 164
    Points
    164
    Par défaut
    Bonsoir,

    Merciiiiiii, et tout le reste a été résolue !!!

    même l'attribution des rôles.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. requete avec la valeur NULL
    Par Hinkel dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 12/11/2008, 16h39
  2. Passer une valeur Null dans un argument de procédure
    Par preempalver dans le forum VBA Access
    Réponses: 5
    Dernier message: 30/12/2003, 20h52
  3. Selectionner un champ de valeur nulle
    Par arcane dans le forum Requêtes
    Réponses: 2
    Dernier message: 30/09/2003, 14h26
  4. [CR9] conversion de valeurs NULL
    Par ministry dans le forum SAP Crystal Reports
    Réponses: 4
    Dernier message: 12/09/2003, 11h41
  5. Valeurs Nulles ou Valeurs à Zéro
    Par LLaurent dans le forum XMLRAD
    Réponses: 5
    Dernier message: 30/07/2003, 11h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo