【发布时间】:2021-09-26 01:16:40
【问题描述】:
在我的 Discord 机器人中,我发出了带有反应的帮助命令。但最近我听说了“按钮”。许多开发人员建议我使用按钮而不是反应。有人知道如何修改我的代码以使消息保持不变吗? 顺便说一下,这是我当前的代码:
@client.command()
async def help(ctx):
contents = [
discord.Embed(title='Utilities commands',description=
f'''
text 1
''',colour=0xF00C0C),
discord.Embed(title='Moderation commands',description=
f'''
text 2
''',colour=0xF00C0C),
discord.Embed(title='Fun commands',description=
f'''
text 3
''',colour=0xF00C0C),
discord.Embed(title='Coding commands',description=
f'''
text 4
''',colour=0xF00C0C),
discord.Embed(title='Bot\'s info | ID: 856643485340139580',description=
'''
text 5
''',colour=0xF00C0C)
]
pages = 5
cur_page = 1
message = await ctx.send(embed=contents[cur_page - 1])
await message.add_reaction("◀️")
await message.add_reaction("▶️")
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ["◀️", "▶️"]
while True:
try:
reaction, user = await client.wait_for("reaction_add", check=check)
if str(reaction.emoji) == "▶️" and cur_page != pages:
cur_page += 1
await message.edit(embed=contents[cur_page - 1])
await message.remove_reaction(reaction, user)
elif str(reaction.emoji) == "◀️" and cur_page > 1:
cur_page -= 1
await message.edit(embed=contents[cur_page - 1])
await message.remove_reaction(reaction, user)
else:
await message.remove_reaction(reaction, user)
except:
break
感谢任何形式的帮助!
【问题讨论】:
标签: python discord discord.py bots