vendredi 31 juillet 2020

Multiple outputs on on_message while using a random number generator

from discord.ext import commands
import discord
import random

class Ship(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    
    @commands.Cog.listener()
    async def on_message(self, message):
        if (message.guild.id == 464298877823221761) or (message.guild.id == 548945695034310697) or (message.guild.id == 712143774935154689):
            if message.content.find("!ship") != -1:
                line = message.content
                name = line.split(' ')[1]
                name2 = line.split(' ')[2]
                number = random.randint(0,100)
                if (number >= 0) or (number <= 10):
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** Awful :sob:')
                    number = random.randint(0,100)
                if (number >= 11) or (number <= 19):
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** Bad :cry:')
                    number = random.randint(0,100)
                if (number >= 20) or (number <= 29):
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** Pretty Low :frowning:')
                    number = random.randint(0,100)
                if (number >= 30) or (number <= 39):
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** Not Great :confused:')
                    number = random.randint(0,100)
                if (number >= 40) or (number <= 49):
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** Not Too Bad :confused:')
                    number = random.randint(0,100)
                if (number >= 50) or (number <= 59):
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** Barely :no_mouth:')
                    number = random.randint(0,100)
                if (number >= 60) or (number <= 69):
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** Not Bad :slight_smile:')
                    number = random.randint(0,100)
                if (number >= 70) or (number <= 79):
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** Pretty Good :smiley:')
                    number = random.randint(0,100)
                if (number >= 80) or (number <= 89):
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** Great :smile:')
                    number = random.randint(0,100)
                if (number >= 90) or (number <= 99):
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** Amazing :heart_eyes:')
                    number = random.randint(0,100)
                if number == 100:
                    await message.channel.send(':heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`' + name +'`'+ '\n:small_red_triangle:`' + name2 + '`' + '\n**' + str(number) + '%** **PERFECT** :heart_exclamation:')
                    number = random.randint(0,100)

def setup(bot):
    bot.add_cog(Ship(bot))

I think that title sums it up, when I type in !ship followed by 2 names the code spits out an answer many times all with different numbers, I think its better if I send a screenshot, if you have any questions I will be online for a few more hours to answer them

https://imgur.com/a/BO72pkv




Aucun commentaire:

Enregistrer un commentaire