mardi 18 août 2020

Python discord bot skips over code or stop working

The first part of this code I made works fine, It pings a random person when I ping the bot, but the 2nd part which pings multiple people breaks and get stuck constantly. It doesn't show any errors on the PyCharm consol, but it doesn't send any of the messages and often I have to restart the bot because it stops working in general.

@client.event
    async def on_message(message):
        channel = message.channel
        if message.author == client.user:
            return
        if client.user.mentioned_in(message):
            output = ""
            boolean = True
            while boolean:
                num = len(message.content) - 1
                try:
                    unused = int(message.content[num])
                except:
                    boolean = False
                if boolean:
                    output = message.content[num] + output
            if output == "":
                randomMember = random.choice(channel.guild.members)
                embed = discord.Embed(title="@random",
                                      description=message.author.mention + " randomly pinged " + randomMember.mention,
                                      color=0xf29718)
                await message.channel.send("||" + message.author.mention + randomMember.mention + "||", embed=embed)
                await discord.Message.delete(message, delay=None)
                return
            elif output >= 11 or output >= len(channel.guild.members):
                embed = discord.Embed(title="Error",
                                      description="You have pinged too many people!",
                                      color=0xec2222)
                await message.channel.send("||" + message.author.mention + "||", embed=embed)
            else:
                randomMembers = []
                for x in range(1, output):
                    randomMember = random.choice(channel.guild.members)
                    while randomMember in randomMembers:
                        randomMember = random.choice(channel.guild.members)
                    randomMembers.append(randomMember)
                output2 = ""
                for y in randomMembers:
                    extra = y
                    output2 = output2 + extra.mention
                embed = discord.Embed(title="@random " + output,
                                      description=message.author.mention + " randomly pinged " + output2,
                                      color=0xf29718)
                await message.channel.send("||" + message.author.mention + output2 + "||", embed=embed)
                await discord.Message.delete(message, delay=None)
                return



Aucun commentaire:

Enregistrer un commentaire