你好,我用表情符号创建了一个游戏,下面是我的代码,它工作正常。
@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))
但是如何使表情符号随机运行,如下图所示。
答案 0 :(得分:1)
基于帕特里克(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))
答案 1 :(得分:0)
为此,您只想运行一次基本循环即可运行多长时间。每次循环时,您都可以编辑消息(.edit
)来更改那里的表情符号。希望有帮助。
答案 2 :(得分:0)
那些是动画表情符号。对该消息进行了三遍编辑,以通过将其替换为静态表情符号来“冻结”该表情符号。我认为您的机器人必须安装在由拥有那些自定义表情符号的Discord Nitro所拥有的服务器中。这样,即使在其他服务器中,您的机器人也可以使用这些表情符号。
答案 3 :(得分:0)
这里是个小伙子,我是一个他妈的自闭症编码者,但这确实可以在我的机器人上运行100%,希望它能起作用,(是的,机器人可以使用动画表情符号来烫发,但因为你不需要,所以将表情符号选择器添加到自定义表情符号列表中后,然后使用ctrl + shift + i检查元素并提取您需要定义的ID,您可以在我的源代码中看到动画表情符号定义的示例,享受:)(idk如何使其成为python,因此如果它看起来很愚蠢,请尝试复制粘贴,否则请与我联系,我可以将里面的文件发送给您。)
#!/bin/bash
while true; do
assist_array=() # reset the array
if pgrep -xq -- "Mail"; then
assist_array+=('It looks like your trying to send an email. Would you like some help?')
fi
if pgrep -xq -- "Notes"; then
assist_array+=('It looks like your trying to take a note. Would you like some help?')
fi
arraylength=${#assist_array[@]}
for ((i=0; i<arraylength; i++)); do
echo "${assist_array[i]}"
say "${assist_array[i]}"
done
# probably put a sleep here
done