python全部代码后退一_反作用分页按钮前进和后退python

这是我想到的。

基本上,我们有一个循环,检查每个反应与我们想要的,然后删除旧消息,并发送新的,如果我们看到我们正在寻找的反应之一。

from discord.ext import commands

bot = commands.Bot(command_prefix='!')

left = 'âª'

right = 'â©'

messages = ("1", "2", "3")

def predicate(message, l, r):

def check(reaction, user):

if reaction.message.id != message.id or user == bot.user:

return False

if l and reaction.emoji == left:

return True

if r and reaction.emoji == right:

return True

return False

return check

@bot.command(pass_context=True)

async def series(ctx):

index = 0

while True:

msg = await bot.say(messages[index])

l = index != 0

r = index != len(messages) - 1

if l:

await bot.add_reaction(msg, left)

if r:

await bot.add_reaction(msg, right)

# bot.wait_for_reaction

react, user = await bot.wait_for_reaction(check=predicate(msg, l, r))

if react.emoji == left:

index -= 1

elif react.emoji == right:

index += 1

await bot.delete_message(msg)

bot.run("TOKEN")

有人要求编辑邮件而不是发送新邮件的版本,我也将其更新为最新版本:

@bot.command(pass_context=True)

async def series(ctx):

index = 0

msg = None

action = ctx.send

while True:

res = await action(content=messages[index])

if res is not None:

msg = res

l = index != 0

r = index != len(messages) - 1

if l:

await msg.add_reaction(left)

if r:

await msg.add_reaction(right)

react, user = await bot.wait_for('reaction_add', check=predicate(msg, l, r))

if react.emoji == left:

index -= 1

elif react.emoji == right:

index += 1

action = msg.edit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值