I want clear or disable reactions in setting time using nextcord.py
I making poll command and wanna delete or disable(I dont know can I or not) reactions in setting time
I have code like this
JavaScript
x
38
38
1
@commands.command()
2
@commands.has_permissions(administrator=True)
3
async def poll(self, ctx, time: int, title, *options):
4
await ctx.message.delete()
5
if time == None:
6
await ctx.send("Укажите время!", delete_after = 5)
7
elif title == None:
8
await ctx.send("Укажите название!", delete_after = 5)
9
elif options == None:
10
await ctx.send("Укажите вопросы!", delete_after = 5)
11
12
13
if len(options) >= 6:
14
await ctx.send("Максимальное количество вопросов - 6!")
15
else:
16
time1 = datetime.now()
17
time2 = timedelta(minutes=time)
18
time_plus = time1 + time2
19
time_plus = nextcord.utils.format_dt(time_plus,style = "T")
20
21
embed = nextcord.Embed(color = 0xFFFFFF, title = title, description=f"""
22
Опроc закончится в {time_plus}n
23
""")
24
embed.set_thumbnail(url = "https://s10.gifyu.com/images/ezgif.com-gif-maker2423fb57189d7e5fb.gif")
25
if len(options) == 1:
26
embed.add_field(name = f"1",value=f"{options[0]}")
27
m = await ctx.send(embed = embed)
28
await m.add_reaction("1️⃣")
29
if datetime.now() == time_plus:
30
m.clear_reaction()
31
32
if len(options) == 2:
33
embed.add_field(name = f"1",value=f"{options[0]}")
34
embed.add_field(name = f"2",value=f"{options[0]}")
35
m = await ctx.send(embed = embed)
36
await m.add_reaction("1️⃣")
37
await m.add_reaction("2️⃣")
38
I have my time time_plus
and wanna do something when time invoke
Advertisement
Answer
You can use reaction.clear
or reaction.remove
to remove reaction from your message.
Here’s an example to remove specific reaction from user by using on_raw_reaction_add
JavaScript
1
13
13
1
@bot.event
2
async def on_raw_reaction_add(payload):
3
channel = await bot.fetch_channel(payload.channel_id)
4
message = await channel.fetch_message(payload.message_id)
5
emoji = payload.emoji.name
6
7
if message.author.id != bot.user.id or payload.member.id == bot.user.id:
8
return
9
if emoji == '1️⃣': #if user react 1️⃣ to your message
10
#do your stuff here
11
reaction = nextcord.utils.get(message.reactions, emoji=emoji)
12
await reaction.remove(payload.member) #remove the reaction
13