Tuesday, 22 November 2022

Check if user react with an certian emoji with cogs

I have a problem. How can I check which emoji the user reacted with? That did not work for me How do you check if a specific user reacts to a specific message [discord.py]

I want to check if the reaction is or

folder structure

├── main.py
├── cogs
│   ├── member.py

The problem is that I don't get an error message. Nothing happens. As soon as I react with an emoji, nothing happens.

member.py

import discord
from discord.ext import commands
from datetime import datetime

class command(commands.Cog):
    def __init__(self, bot):
        self.bot = bot



    @commands.Cog.listener()
    async def on_message(self, message):
            ...
                 ...
                    for emoji in emojis:
                        await msg.add_reaction(emoji)



                    await message.author.send('Send me that ✅ reaction, mate')

                    def check(reaction, user):
                        return user == message.author and str(reaction.emoji) == '✅'

                    res = await self.bot.wait_for(
                        "reaction_add",
                        check=check, timeout=None
                    )
                    print(res.emoji)

                    if res.content.lower() == "✅":
                        await message.author.send("Got it")
                    else:
                        await message.author.send("Thanks")
                    
                    confirmation = await self.bot.wait_for("reaction_add", check=check)
                    await message.author.send("You responded with {}".format(reaction.emoji))


async def setup(bot):
    await bot.add_cog(command(bot))
import asyncio
import os

from dotenv import load_dotenv

import discord
from discord.ext import commands
from discord.ext.commands import has_permissions

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')

import discord
from discord.utils import get

  
    
class MyBot(commands.Bot):

    def __init__(self):
        intents = discord.Intents.default()
        intents.message_content = True

        super().__init__(command_prefix=commands.when_mentioned_or('-'), intents=intents, max_messages=1000)

    async def on_ready(self):
        print(f'Logged in as {self.user} (ID: {self.user.id})')

    async def setup_hook(self):
        for file in os.listdir("./cogs"):
            if file.endswith(".py"):
                extension = file[:-3]
                try:
                    await self.load_extension(f"cogs.{extension}")
                    print(f"Loaded extension '{extension}'")
                except Exception as e:
                    exception = f"{type(e).__name__}: {e}"
                    print(f"Failed to load extension {extension}\n{exception}")

bot = MyBot()

bot.run(TOKEN)


from Check if user react with an certian emoji with cogs

No comments:

Post a Comment