Je débute le python, j'essaye d'ajouter une commande à mon code, mais je n'y arrive pas très bien... je ne connais pas beaucoup la syntaxe et donc je fais beaucoup d'erreur, à l'aide d'internet j'ai réussi à écrire quelques trucs... et j'ai fais ça :
async def cmd_commande1(self, channel):
orig_msg = _get_variable('message')
a = random.randrange(1,5)
if orig_msg.author.id == self.config.owner_id:
if a == 1:
return await self.safe_send_message(channel, "Réponse 1")
elif a == 2:
return await self.safe_send_message(channel, "Réponse 2")
elif a == 3:
return await self.safe_send_message(channel, "Réponse 3")
elif a == 4:
return await self.safe_send_message(channel, "Réponse 4")
else:
if a == 1:
return await self.safe_send_message(channel, "Réponse 1bis")
elif a == 2:
return await self.safe_send_message(channel, "Réponse 2bis")
elif a == 3:
return await self.safe_send_message(channel, "Réponse 3bis")
elif a == 4:
return await self.safe_send_message(channel, "Réponse 4bis")
return wrapper
Désolé si je vous ai brûlé les yeux
Mon problème c'est que je voudrais mettre des if en fonctions de deux conditions, la première lorsque orig_msg.author == self.config.owner.id
et la deuxième en fonction de la valeur de a, qui est défini "aléatoirement" entre 1 et 4.
Sauf que ça ne fonctionne pas... Donc j'ai essayé une autre méthode, un peu plus développée, en faisant :
async def cmd_jtm(self, channel):
orig_msg = _get_variable('message')
a = random.randrange(1,5)
if orig_msg.author.id == self.config.owner_id and a == 1:
return await self.safe_send_message(channel, "Reponse1")
elif orig_msg.author.id == self.config.owner_id and a == 2:
return await self.safe_send_message(channel, "Reponse2")
elif orig_msg.author.id == self.config.owner_id and a == 3:
return await self.safe_send_message(channel, "Reponse3")
elif orig_msg.author.id == self.config.owner_id and a == 4:
return await self.safe_send_message(channel, "Reponse4")
elif orig_msg.author.id != self.config.owner_id and a == 1:
return await self.safe_send_message(channel, "Reponse1bis")
elif orig_msg.author.id != self.config.owner_id and a == 2:
return await self.safe_send_message(channel, "Reponse2bis")
elif orig_msg.author.id != self.config.owner_id and a == 3:
return await self.safe_send_message(channel, "Reponse3bis")
elif orig_msg.author.id != self.config.owner_id and a == 4:
return await self.safe_send_message(channel, "Reponse4bis")
return wrapper
Désolé d'avoir achevé vos yeux
à chaque fois j'obtiens l'erreur
Voilà.. donc le petit débutant que je suis, implore votre aide, comment faire cette double conditions ?
Merci d'avance
EDIT : C'était une erreur de syntaxe, j'ai pas trop compris mais ça marche maintenant.
Résolu
- Edité par Anonyme 20 décembre 2016 à 16:59:41
Problème multiple conditions (bot discord)
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.