Search code examples
pythondiscordbots

discord.ext: message.content and others not working


I'm developing a discord bot, and it manages to collect all info but a message's content. I've tried to add intents but then it just returns this error:

Traceback (most recent call last):
  File "C:\Users\jbart\Documents\MemoBot\Run.py", line 23, in <module>
    Bot.run(BotClient.token)
  File "C:\Users\jbart\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 723, in run
    return future.result()
  File "C:\Users\jbart\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 702, in runner
    await self.start(*args, **kwargs)
  File "C:\Users\jbart\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 666, in start
    await self.connect(reconnect=reconnect)
  File "C:\Users\jbart\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 601, 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.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000019ACDCCB760>
Traceback (most recent call last):
  File "C:\Users\jbart\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\jbart\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\jbart\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 750, in call_soon
    self._check_closed()
  File "C:\Users\jbart\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 515, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

I'm using a custom bot creator I've made, it's very simple:

import discord
from discord.ext import commands

intents = discord.Intents.all()

class Astro:
    def __init__(self, token, prefix='/'):
        self.bot = commands.Bot(command_prefix=prefix, intents=intents)
        self.token = token

    async def on_ready(self):
        print(f'Bot is ready. @{self.bot.user}')

    def run(self):
        self.bot.run(self.token)

def new(token, prefix='/'):
    bot = Astro(token, prefix)
    return bot

as for the main code,

import Astro

BotClient = Astro.new("TOKEN", prefix='/')
Bot = BotClient.bot


@Bot.event
async def on_ready():
    print(f'Bot is ready. @{Bot.user}')


@Bot.event
async def on_message(message):
    # Get the message, author and channel name
    msg = str(message.clean_content)
    author = message.author
    channel_name = message.channel.name
    # Write the message, author, and channel name to the log file
    with open("messages.log", "a") as f:
        f.write(f"{msg} | {author} | {channel_name}\n") # the log file doesn't show the content.


Bot.run(BotClient.token)

I have no idea what is going on and have searched the internet for fixes but all just return more and more errors. What's supposed to happen is it prints "Bot is ready. @MemoBot#3249" and each time somebody messages something it stores the data. (This part is for testing and not in the final product), but instead it just throws the error before the bot can run.


Solution

  • Nevermind! For anyone else having this problem, you don't need to focus in on the URL Generator or anywhere like that, but the bot section- and then the Privileged Gateway Intents instead. I was probably just reading it incorrectly, but toggle all of them and you should be good to go!