我编写的这段代码的第一部分工作正常,当我对机器人进行ping操作时,它会对一个随机的人执行ping操作,但是对多人执行ping操作的第二部分会断裂并不断卡住。它在PyCharm consol上没有显示任何错误,但是它没有发送任何消息,而且由于它通常无法正常工作,我经常不得不重新启动该机器人。
@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