0

Я написал бот дискорд который выдает роли по эмодзи, но при запуске пишет ошибку вот код:

import discord
import config

intents = discord.Intents.default()
intents.members = True


class DiscordBot(discord.Client):
    async def on_ready(self):
        print(f"Бот {self.user} в сети")

    async def on_raw_reaction_add(self, paylood):
        if paylood.message.id == config.ID_POST:
            channel = self.get_channel(paylood.channel_id)
            message = await channel.fetch_message(paylood.message_id)
            user = discord.utils.get(message.guild.members, id=paylood.user_id)
            emoji = str(paylood.emoji)

            try:
                role = discord.utils.get(message.guild.roles, id=config.ROLE_LIST(emoji))

                if len([i for i in user.roles if i.id not in config.USER_ROLES_LIST]) <= config.MAX_ROLES:
                    await user.add_roles(role)
                    print(f"{user.name} получил роль {role.name}")
                else:
                    await message.remove_reaction(paylood.emoji, user)
                    print(f"Ошибка! пользователь {user.name} пытался получить слишком много ролей")

            except Exception as _ex:
                print(repr(_ex))

    async def on_raw_reaction_remove(self, paylood):
        channel = self.get_channel(paylood.channel_id)
        message = await channel.fetch_message(paylood.message_id)
        user = discord.utils.get(message.guild.members, id=paylood.user_id)

        try:
            emoji = str(paylood.emoji)
            role = discord.utild.get(message.guild.roles, id=config.ROLE_LIST[emoji])
            await user.remove_roles(role)
        except Exception as _ex:
            print(repr(_ex))


client = DiscordBot(intents=intents)
client.run(config.BOT_TOKEN)

вот config.py

BOT_TOKEN = "тОКЕН"
ID_POST = 0
USER_ROLES_LIST = ()
MAX_ROLES = 3

ROLE_LIST = {
    "✅": 1051595649646338118, #Верифицированый
}

вот ошибка Traceback (most recent call last): File "C:\Users\hadji\PycharmProjects\pythonProject\dsrolebot\rolebot.py", line 46, in client.run(config.BOT_TOKEN) File "C:\Users\hadji\PycharmProjects\pythonProject\venv\lib\site-packages\discord\client.py", line 828, in run asyncio.run(runner()) File "C:\Users\hadji\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run return loop.run_until_complete(main) File "C:\Users\hadji\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete return future.result() File "C:\Users\hadji\PycharmProjects\pythonProject\venv\lib\site-packages\discord\client.py", line 817, in runner await self.start(token, reconnect=reconnect) File "C:\Users\hadji\PycharmProjects\pythonProject\venv\lib\site-packages\discord\client.py", line 746, in start await self.connect(reconnect=reconnect) File "C:\Users\hadji\PycharmProjects\pythonProject\venv\lib\site-packages\discord\client.py", line 672, in connect raise PrivilegedIntentsRequired(exc.shard_id) from None discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.

1
  • Укажите в вопросе, какую конкретно ошибку пишет
    – insolor
    11 дек 2022 в 20:59

1 ответ 1

0

Да. Просто проверьте, есть ли у пользователя проверенная роль:

@bot.event
async def on_raw_reaction_add(payload):
    if payload.channel_id == :
        guild_id = payload.guild_id
        guild = discord.utils.find(lambda g: g.id == guild_id, bot.guilds)

        if payload.emoji.name == '✅':
            role = discord.utils.get(guild.roles, name='Verified')
            role2 = discord.utils.get(guild.roles, name='Not-Verified')

            if role is not None:
                msg = await bot.get_channel(payload.channel_id).fetch_message(payload.message_id)
                member = msg.author
                channel = await member.create_dm()
                if member is not None and role not in member.roles:
                    await member.add_roles(role)
                    await member.remove_roles(role2)
                    await channel.send("You have been Verified!")
                    print('done')
                else:
                    print('member not found or user already has role')

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.