【问题标题】:403 Forbidden (error code: 50001): Missing Access [discord.py]403 禁止(错误代码:50001):缺少访问权限 [discord.py]
【发布时间】:2022-01-17 22:06:10
【问题描述】:

每当我尝试运行我的程序时,我都会收到此错误,我尝试为其授予除管理员之外的所有可能的权限,但它仍然无法运行,它仅在我授予它管理员权限时运行,

错误发生在 on_ready 事件上

这是我的代码

@client.event
async def on_ready():
    print('------')
    print('Online! Details:')
    print(f"Bot Username: {client.user.name}")
    print(f"BotID: {client.user.id}")
    print('------')
    data = pd.DataFrame(columns=['channel','author'])
    text_channel_list = []
    for i in guild:
      g = client.get_guild(i)
   
      for channel in g.channels:
        if str(channel.type) == 'text':
          text_channel_list.append(channel)
    
    for j in text_channel_list:
      channel = client.get_channel(j.id)
      
      async for msg in channel.history(limit=100000):
        if msg.author != client.user:                                                              
                data = data.append({'channel':msg.channel.name,
                                    'author': msg.author}, ignore_index=True)
        if len(data) == 100000:
            break
        
      file_location = "data.csv"
      data.to_csv(file_location)
    await asyncio.sleep(60)
    client.loop.create_task(on_ready())

这是错误

------
Online! Details:
Bot Username: Giveaway Bot Dev
BotID: 920320119878602752
------
Ignoring exception in on_ready
Traceback (most recent call last):
  File "C:\Users\hires\AppData\Roaming\Python\Python39\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "d:\Freelance Giveaway Bot\main.py", line 95, in on_ready
    async for msg in channel.history(limit=100000):
  File "C:\Users\hires\AppData\Roaming\Python\Python39\site-packages\discord\iterators.py", line 91, in __anext__
    msg = await self.next()
  File "C:\Users\hires\AppData\Roaming\Python\Python39\site-packages\discord\iterators.py", line 285, in next
    await self.fill_messages()
  File "C:\Users\hires\AppData\Roaming\Python\Python39\site-packages\discord\iterators.py", line 328, in fill_messages
    data = await self._retrieve_messages(self.retrieve)
  File "C:\Users\hires\AppData\Roaming\Python\Python39\site-packages\discord\iterators.py", line 348, in _retrieve_messages_before_strategy
    data = await self.logs_from(self.channel.id, retrieve, before=before)
  File "C:\Users\hires\AppData\Roaming\Python\Python39\site-packages\discord\http.py", line 248, in request
    raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access

编辑 所有这些权限都已授予。

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    也许尝试使用不同的代码?像这样:

    messages = await channel.history(limit=10000)
    
    for i, message in enumerate(messages):
        message = message.content
        if message.author != client.user:                                                              
            data = data.append({'channel':msg.channel.name,'author': msg.author}, ignore_index=True)
    

    或者类似的?

    【讨论】:

    • 我已经给它烫发了
    • 你能截图给我看看吗?
    • @HireshVerma 尝试同时给它阅读消息和阅读消息历史记录
    • 我已经编辑了问题
    • @HireshVerma 哦,这真的很奇怪,我不知道...您可能必须使用管理员权限。
    【解决方案2】:

    我发现我服务器中频道上的一些内容是私有的,机器人无法访问它们,这就是它返回缺少访问错误的原因,我用一个简单的 try-except 修复了它

        for j in text_channel_list:
          channel = client.get_channel(j.id)
          try:
            async for msg in channel.history(limit=100000):   
              if msg.author != client.user:                                                              
                data = data.append({'channel':msg.channel.name,
                                    'author': msg.author}, ignore_index=True)
              if len(data) == 100000:
                  break
          except:
            continue
    

    【讨论】:

    • 也许接受你的回答,让其他人知道。
    • 我可以在 2 天后接受我的回答
    猜你喜欢
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 2019-11-11
    • 2015-04-19
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多