在设置时间内明确反应 [nextcord.py]
Clear reactions in setting time [nextcord.py]
我想使用 nextcord.py
清除或禁用设置时间的反应
我正在执行轮询命令并想在设置时间内删除或禁用(我不知道我能不能)反应
我有这样的代码
@commands.command()
@commands.has_permissions(administrator=True)
async def poll(self, ctx, time: int, title, *options):
await ctx.message.delete()
if time == None:
await ctx.send("Укажите время!", delete_after = 5)
elif title == None:
await ctx.send("Укажите название!", delete_after = 5)
elif options == None:
await ctx.send("Укажите вопросы!", delete_after = 5)
if len(options) >= 6:
await ctx.send("Максимальное количество вопросов - 6!")
else:
time1 = datetime.now()
time2 = timedelta(minutes=time)
time_plus = time1 + time2
time_plus = nextcord.utils.format_dt(time_plus,style = "T")
embed = nextcord.Embed(color = 0xFFFFFF, title = title, description=f"""
Опроc закончится в {time_plus}\n
""")
embed.set_thumbnail(url = "https://s10.gifyu.com/images/ezgif.com-gif-maker2423fb57189d7e5fb.gif")
if len(options) == 1:
embed.add_field(name = f"1",value=f"{options[0]}")
m = await ctx.send(embed = embed)
await m.add_reaction("1️⃣")
if datetime.now() == time_plus:
m.clear_reaction()
if len(options) == 2:
embed.add_field(name = f"1",value=f"{options[0]}")
embed.add_field(name = f"2",value=f"{options[0]}")
m = await ctx.send(embed = embed)
await m.add_reaction("1️⃣")
await m.add_reaction("2️⃣")
我有时间time_plus
并且想在时间调用时做点什么
您可以使用 reaction.clear
or reaction.remove
删除消息中的反应。
这是一个使用 on_raw_reaction_add
删除用户特定反应的示例
@bot.event
async def on_raw_reaction_add(payload):
channel = await bot.fetch_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
emoji = payload.emoji.name
if message.author.id != bot.user.id or payload.member.id == bot.user.id:
return
if emoji == '1️⃣': #if user react 1️⃣ to your message
#do your stuff here
reaction = nextcord.utils.get(message.reactions, emoji=emoji)
await reaction.remove(payload.member) #remove the reaction
我想使用 nextcord.py
清除或禁用设置时间的反应我正在执行轮询命令并想在设置时间内删除或禁用(我不知道我能不能)反应
我有这样的代码
@commands.command()
@commands.has_permissions(administrator=True)
async def poll(self, ctx, time: int, title, *options):
await ctx.message.delete()
if time == None:
await ctx.send("Укажите время!", delete_after = 5)
elif title == None:
await ctx.send("Укажите название!", delete_after = 5)
elif options == None:
await ctx.send("Укажите вопросы!", delete_after = 5)
if len(options) >= 6:
await ctx.send("Максимальное количество вопросов - 6!")
else:
time1 = datetime.now()
time2 = timedelta(minutes=time)
time_plus = time1 + time2
time_plus = nextcord.utils.format_dt(time_plus,style = "T")
embed = nextcord.Embed(color = 0xFFFFFF, title = title, description=f"""
Опроc закончится в {time_plus}\n
""")
embed.set_thumbnail(url = "https://s10.gifyu.com/images/ezgif.com-gif-maker2423fb57189d7e5fb.gif")
if len(options) == 1:
embed.add_field(name = f"1",value=f"{options[0]}")
m = await ctx.send(embed = embed)
await m.add_reaction("1️⃣")
if datetime.now() == time_plus:
m.clear_reaction()
if len(options) == 2:
embed.add_field(name = f"1",value=f"{options[0]}")
embed.add_field(name = f"2",value=f"{options[0]}")
m = await ctx.send(embed = embed)
await m.add_reaction("1️⃣")
await m.add_reaction("2️⃣")
我有时间time_plus
并且想在时间调用时做点什么
您可以使用 reaction.clear
or reaction.remove
删除消息中的反应。
这是一个使用 on_raw_reaction_add
@bot.event
async def on_raw_reaction_add(payload):
channel = await bot.fetch_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
emoji = payload.emoji.name
if message.author.id != bot.user.id or payload.member.id == bot.user.id:
return
if emoji == '1️⃣': #if user react 1️⃣ to your message
#do your stuff here
reaction = nextcord.utils.get(message.reactions, emoji=emoji)
await reaction.remove(payload.member) #remove the reaction