简体   繁体   English

discord.ext: message.content 和其他不工作

[英]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.我正在开发一个 discord 机器人,它设法收集除消息内容之外的所有信息。 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 inte.net for fixes but all just return more and more errors.我不知道发生了什么,并在 inte.net 上搜索了修复程序,但都返回了越来越多的错误。 What's supposed to happen is it prints "Bot is ready. @MemoBot#3249" and each time somebody messages something it stores the data.应该发生的是它打印“Bot is ready.@MemoBot#3249”并且每次有人发送消息时它都会存储数据。 (This part is for testing and not in the final product), but instead it just throws the error before the bot can run. (这部分是为了测试而不是在最终产品中),而是它只是在机器人运行之前抛出错误。

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.对于遇到此问题的任何其他人,您无需关注 URL 生成器或类似的任何地方,而是机器人部分 - 然后是特权网关意图。 I was probably just reading it incorrectly, but toggle all of them and you should be good to go!我可能只是读错了,但是切换所有这些,你应该很高兴!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM