from discord.ext import commandsimport discordimport randomclass 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 0 <= 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 11 <= 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 20 <= 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 30 <= 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 40 <= number <= 49:我认为标题总结了它,当我打开机器人并输入!ship后跟 2 个名称时,代码会吐出 2 条消息,但第二次输入命令时,我会按预期获得 1 个输出请查看此问题的评论以获取有关我的问题的更多信息
1 回答
HUH函数
TA贡献1836条经验 获得超4个赞
你的问题出在你的条件上。
例如,参见第一个条件:
if (number >= 0) or (number <= 10):
这将需要任何数字。你想要 number >= 0 AND number <= 10。
顺便说一句,你可以这样做:
if 0 <= number <= 10:
此外,您不应该在每种情况下随机分配一个新数字。
最后一件事,你似乎是 10 乘 10 做的,所以你可以做一些更容易的事情,比如:
labels = {0: "awful", 1: "bad", 2 : "decent", ...}
number = random.randint(0,100)
label = labels[int(number/10)]
await message.channel.send(
f"heartpulse:**MATCHMAKING**:heartpulse:\n
:small_red_triangle_down:`{name}`\n
:small_red_triangle:`{name2}`\n
**{number}%** **{label}** :heart_exclamation:")
添加回答
举报
0/150
提交
取消