Python 3.x 不和谐机器人游戏表情符号

Python 3.x 不和谐机器人游戏表情符号,python-3.x,discord.py,Python 3.x,Discord.py,你好,我用表情符号创建了一个游戏,下面是我的代码,工作正常 @bot.command(pass_context=True) async def game(ctx): slots = ['bus', 'train', 'horse', 'tiger', 'monkey', 'cow'] slot1 = slots[random.randint(0, 5)] slot2 = slots[random.randint(0, 5)] slotOutput = '| :{

你好,我用表情符号创建了一个游戏,下面是我的代码,工作正常

@bot.command(pass_context=True)
async def game(ctx):
    slots = ['bus', 'train', 'horse', 'tiger', 'monkey', 'cow']
    slot1 = slots[random.randint(0, 5)]
    slot2 = slots[random.randint(0, 5)]

    slotOutput = '| :{}: | :{}: |\n'.format(slot1, slot2)

    if slot1 == slot2:
        await bot.send_message(ctx.message.channel, "{}\nWon".format(slotOutput))

    else:
        await bot.send_message(ctx.message.channel, "{}\nLost".format(slotOutput))

但如何使表情符号在随机选择中运行,如下图所示。

要做到这一点,您只需执行一个基本循环,运行多长时间。每次它循环时,你都会编辑消息。编辑以更改那里的表情。希望有帮助。

这些是动画表情符号。该消息将被编辑三次,以通过将其替换为静态表情符号来冻结表情符号。我相信你的机器人需要在一个服务器中,由一个与那些自定义表情符号不一致的Nitro拥有。这样你的机器人就可以在其他服务器上使用这些表情符号了

基于Patrick的回答,您似乎只是立即发布结果,而您想做的是发布车轮旋转,然后将其编辑到结果中

# You shouldn't trust Discord to handle :emotes: properly. For unicode
# emotes, use the codepoint \N{NAME} or \U0001Fxxx, for custom emotes
# use <:_:EMOTE_ID> or <a:_:ANIMOTE_ID>
slots = ["\N{MONKEY FACE}", "\N{COW FACE}", "\N{TIGER_FACE}", 
         "\N{HORSE FACE}", "\N{BUS}", "\N{STEAM LOCOMOTIVE}"]

# choice(v) is same as v[randrange(len(v))]
results = [random.choice(slots), random.choice(slots)]

msg = await bot.send_message("| {0} | {0} |".format("<a:slot_spin:EMOJI_ID>"))
# Note you will need to create the emote and put it on a server the bot can see

for show in range(len(results)):
    await asyncio.sleep(random.uniform(1, 4))
    disp = [v if show <= i else "<a:_:...>" # Only show indexes below the show number
            for i, v in enumerate(results)] # enumerate returns [(0, results[0]), ...]
    bot.edit_message(msg, "| {0[0]} | {0[1]} |".format(disp))

给你,小伙子,我是一个他妈的自闭症编码员,但现在它在我的机器人上运行,100%有效,希望能有所帮助,是的,机器人有烫发来使用动画表情,但是因为你不需要在添加到你的自定义表情列表后,在discord中转到表情选择器,然后执行ctrl+shift+i来检查元素并提取你需要定义的元素ID,你可以在我的源代码中看到动画表情定义的示例,享受:idk如何使它后成为python,所以如果它看起来愚蠢idk尝试复制粘贴它,否则与我联系,我可以只发送给你里面的文件

@bot.command()
async def game(ctx):
await ctx.message.delete()
parrot = '<a:parrot:498460603300446238>'
slotspin = '<a:heartgif:498082283077500938>'
slots = [':blue_heart:', ':blue_heart:', ':blue_heart:', ':purple_heart:', ':heart:', ':yellow_heart:', ':green_heart:', ':green_heart:', ':green_heart:', ':green_heart:', ':green_heart:', ':green_heart:']
slot1 = slots[random.randint(0, 11)]
slot2 = slots[random.randint(0, 11)]
slot3 = slots[random.randint(0, 11)]
slot4 = slots[random.randint(0, 11)]
slot5 = slots[random.randint(0, 11)]
slot6 = slots[random.randint(0, 11)]
slot7 = slots[random.randint(0, 11)]
slot8 = slots[random.randint(0, 11)]
slot9 = slots[random.randint(0, 11)]
slot10 = slots[random.randint(0, 11)]
slot11 = slots[random.randint(0, 11)]
slot12 = slots[random.randint(0, 11)]
slot13 = slots[random.randint(0, 11)]
slot14 = slots[random.randint(0, 11)]
slot15 = slots[random.randint(0, 11)]
slot16 = slots[random.randint(0, 11)]
slot17 = slots[random.randint(0, 11)]
slot18 = slots[random.randint(0, 11)]
slot19 = slots[random.randint(0, 11)]
slot20 = slots[random.randint(0, 11)]
slot21 = slots[random.randint(0, 11)]
slot22 = slots[random.randint(0, 11)]
slot23 = slots[random.randint(0, 11)]
slot24 = slots[random.randint(0, 11)]
slot25 = slots[random.randint(0, 11)]

slotOutput = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slot1, slot2, slot3, slot4, slot5, slot6, slot7, slot8, slot9, slot10, slot11, slot12, slot13, slot14, slot15, slot16, slot17, slot18, slot19, slot20, slot21, slot22, slot23, slot24, slot25)
slotOutput1 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin, slotspin,)
results0 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(parrot, parrot, parrot, parrot, parrot, slot6, slot7, slot8, slot9, slot10, slot11, slot12, slot13, slot14, slot15, slot16, slot17, slot18, slot19, slot20, slot21, slot22, slot23, slot24, slot25)
results1 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slot1, slot2, slot3, slot4, slot5, parrot, parrot, parrot, parrot, parrot, slot11, slot12, slot13, slot14, slot15, slot16, slot17, slot18, slot19, slot20, slot21, slot22, slot23, slot24, slot25)
results2 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slot1, slot2, slot3, slot4, slot5, slot6, slot7, slot8, slot9, slot10, parrot, parrot, parrot, parrot, parrot, slot16, slot17, slot18, slot19, slot20, slot21, slot22, slot23, slot24, slot25)
results3 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slot1, slot2, slot3, slot4, slot5, slot6, slot7, slot8, slot9, slot10, slot11, slot12, slot13, slot14, slot15, parrot, parrot, parrot, parrot, parrot, slot21, slot22, slot23, slot24, slot25)
results4 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slot1, slot2, slot3, slot4, slot5, slot6, slot7, slot8, slot9, slot10, slot11, slot12, slot13, slot14, slot15, slot16, slot17, slot18, slot19, slot20, parrot, parrot, parrot, parrot, parrot)
results5 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(parrot, slot2, slot3, slot4, slot5, parrot, slot7, slot8, slot9, slot10, parrot, slot12, slot13, slot14, slot15, parrot, slot17, slot18, slot19, slot20, parrot, slot22, slot23, slot24, slot25)
results6 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slot1, parrot, slot3, slot4, slot5, slot6, parrot, slot8, slot9, slot10, slot11, parrot, slot13, slot14, slot15, slot16, parrot, slot18, slot19, slot20, slot21, parrot, slot23, slot24, slot25)
results7 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slot1, slot2, parrot, slot4, slot5, slot6, slot7, parrot, slot9, slot10, slot11, slot12, parrot, slot14, slot15, slot16, slot17, parrot, slot19, slot20, slot21, slot22, parrot, slot24, slot25)
results8 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slot1, slot2, slot3, parrot, slot5, slot6, slot7, slot8, parrot, slot10, slot11, slot12, slot13, parrot, slot15, slot16, slot17, slot18, parrot, slot20, slot21, slot22, slot23, parrot, slot25)
results9 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slot1, slot2, slot3, slot4, parrot, slot6, slot7, slot8, slot9, parrot, slot11, slot12, slot13, slot14, parrot, slot16, slot17, slot18, slot19, parrot, slot21, slot22, slot23, slot24, parrot)
results10 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(parrot, slot2, slot3, slot4, slot5, slot6, parrot, slot8, slot9, slot10, slot11, slot12, parrot, slot14, slot15, slot16, slot17, slot18, parrot, slot20, slot21, slot22, slot23, slot24, parrot)
results11 = '| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n'.format(slot1, slot2, slot3, slot4, parrot, slot6, slot7, slot8, parrot, slot10, slot11, slot12, parrot, slot14, slot15, slot16, parrot, slot18, slot19, slot20, parrot, slot22, slot23, slot24, slot25)

msg = await ctx.message.channel.send("{}\n {} Is Spinning".format(slotOutput1,ctx.message.author.mention))
await asyncio.sleep(2)
await msg.edit(content='| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n {} Is Spinning'.format(slot1, slotspin, slotspin, slotspin, slotspin, slot6, slotspin, slotspin, slotspin, slotspin, slot11, slotspin, slotspin, slotspin, slotspin, slot16, slotspin, slotspin, slotspin, slotspin, slot21, slotspin, slotspin, slotspin, slotspin, ctx.message.author.mention))
await asyncio.sleep(2)
await msg.edit(content='| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n {} Is Spinning'.format(slot1, slot2, slotspin, slotspin, slotspin, slot6, slot7, slotspin, slotspin, slotspin, slot11, slot12, slotspin, slotspin, slotspin, slot16, slot17, slotspin, slotspin, slotspin, slot21, slot22, slotspin, slotspin, slotspin, ctx.message.author.mention))
await asyncio.sleep(2)
await msg.edit(content='| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n {} Is Spinning'.format(slot1, slot2, slot3, slotspin, slotspin, slot6, slot7, slot8, slotspin, slotspin, slot11, slot12, slot13, slotspin, slotspin, slot16, slot17, slot18, slotspin, slotspin, slot21, slot22, slot23, slotspin, slotspin, ctx.message.author.mention))
await asyncio.sleep(2)
await msg.edit(content='| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n {} Is Spinning'.format(slot1, slot2, slot3, slot4, slotspin, slot6, slot7, slot8, slot9, slotspin, slot11, slot12, slot13, slot14, slotspin, slot16, slot17, slot18, slot19, slotspin, slot21, slot22, slot23, slot24, slotspin, ctx.message.author.mention))
await asyncio.sleep(2)
await msg.edit(content='| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n| {} | {} | {} | {} | {} |\n {} Is Spinning'.format(slot1, slot2, slot3, slot4, slot5, slot6, slot7, slot8, slot9, slot10, slot11, slot12, slot13, slot14, slot15, slot16, slot17, slot18, slot19, slot20, slot21, slot22, slot23, slot24, slot25, ctx.message.author.mention))

if slot1 == slot2 == slot3 == slot4 == slot5:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results0,ctx.message.author.mention),delete_after=3)
elif slot6 == slot7 == slot8 == slot9 == slot10:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results1,ctx.message.author.mention),delete_after=3)
elif slot11 == slot12 == slot13 == slot14 == slot15:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results2,ctx.message.author.mention),delete_after=3)
elif slot16 == slot17 == slot18 == slot19 == slot20:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results3,ctx.message.author.mention),delete_after=3)
elif slot21 == slot22 == slot23 == slot24 == slot25:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results4,ctx.message.author.mention),delete_after=3)
elif slot1 == slot6 == slot11 == slot16 == slot21:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results5,ctx.message.author.mention),delete_after=3)
elif slot2 == slot7 == slot12 == slot17 == slot22:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results6,ctx.message.author.mention),delete_after=3)
elif slot3 == slot8 == slot13 == slot18 == slot23:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results7,ctx.message.author.mention),delete_after=3)
elif slot4 == slot9 == slot14 == slot19 == slot24:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results8,ctx.message.author.mention),delete_after=3)
elif slot5 == slot10 == slot15 == slot20 == slot25:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results9,ctx.message.author.mention),delete_after=3)
elif slot1 == slot7 == slot13 == slot19 == slot25:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results10,ctx.message.author.mention),delete_after=3)
elif slot5 == slot9 == slot13 == slot17 == slot21:
    #await ctx.message.channel.send( "{}\n {} You Won".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Won".format(results11,ctx.message.author.mention),delete_after=3)
else:
    #await ctx.message.channel.send("{}\n {} You Lost".format(slotOutput,ctx.message.author.mention),delete_after=5)
    await msg.edit(content="{}\n {} You Lost".format(slotOutput,ctx.message.author.mention),delete_after=3)

是的,我有Nitro,所以如何做任何示例代码?不,我以前从未做过,我没有Nitro。我建议将其分为两个实验:显示动画循环表情,可能来自不同的服务器,并编辑嵌入,将其冻结在最终位置。所以,你能检查一下它,并帮助我编辑我的代码,如果可能的话。您需要进行3次单独的编辑。一次编辑显示[1][?][?],第二次编辑显示[1][2][?],然后第三次编辑显示所有3个表情停止。e:2个单独的编辑,因为你的老虎机只有2个轮子。动画表情符号的语法是必要的,还是可以用discord表示。表情符号对象?@Patrick Haugh语法是将它们添加到消息中的最简单方法,加上OP使用的in/async,不和谐。表情符号甚至不能区分动画表情符号和普通表情符号。@Demory是的,这就是你要添加到命令函数中的代码。修复了。括号未关闭。请阅读评论。您需要创建一个动画表情供机器人使用,然后替换该表情的ID。在发布到聊天室之前,您可以通过在emote前面加\\前缀来查看它的ID,例如\:ablobcatbounce:will post,这就是您需要粘贴的内容。很简单。调用该命令时,您将发送一条带有三个emoji的消息。然后,你将做一个循环,在这个循环中,你将随机创建组合。您将使用这些随机表情创建一个新的嵌入,并使用新表情编辑旧表情。我假设您使用的是异步,所以如果您需要帮助,请使用或其他方法,好吧,生活是不公平的-您不可能总是得到您想要的。对不起,这是事实。在我的回答和评论中,我也给了你一些好的建议和文字教程。