我的 on_member_join 事件不起作用。我尝试了意图,但它给出了这个错误

问题描述 投票:0回答:1

考虑:

最近一次通话最后): 文件“randomgg.py”,第 1271 行,位于 \u003cmodule\u003e 中 客户端.运行(令牌) 文件“/usr/local/lib/python3.8/site-packages/discord/client.py”,第 708 行,运行中 返回 future.result() 文件“/usr/local/lib/python3.8/site-packages/discord/client.py”,第 687 行,在运行程序中 等待 self.start(*args, **kwargs) 文件“/usr/local/lib/python3.8/site-packages/discord/client.py”,第 651 行,在 start 中 等待 self.connect(重新连接=重新连接) 文件“/usr/local/lib/python3.8/site-packages/discord/client.py”,第 586 行,在连接中 从 None 引发 PrivilegedIntentsRequired(exc.shard_id) Discord.errors.PrivilegedIntentsRequired:分片 ID None 正在请求尚未在开发人员门户中显式启用的特权意图。建议访问 https://discord.com/developers/applications/ 并在应用程序页面中显式启用特权意图。如果这是不可能的,那么请考虑禁用特权意图。

我的代码是

import aiohttp
import discord
import asyncio
from collections import Counter
import typing
from discord.ext import commands
import os
from discord.ext.commands import has_permissions
import random
import json
from discord import Status
from asyncio import gather
from discord.utils import get
import datetime
from discord.utils import get
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='.', intents=intents)
client.remove_command('help')

def check_if_it_is_me(ctx):
    return ctx.message.author.id == 465946367622381578

@client.event
async def status_task():
    while True:
        await client.change_presence(status=discord.Status.idle, activity=discord.Game('status1'))
        await asyncio.sleep(4)
        await client.change_presence(status=discord.Status.idle, activity=discord.Game('status2'))
        await asyncio.sleep(4)
        await client.change_presence(status=discord.Status.idle, activity=discord.Game('status3'))
        await asyncio.sleep(4)

@client.event
async def on_ready():
    print(f'{client.user.name} is ready')
    client.loop.create_task(status_task())

@client.event
async def on_member_join(member):
    mem_join = member.joined_at
    guild_create = member.created_at
    join_days = (mem_join - guild_create).days
    role = discord.utils.get(member.guild.roles, id=714805001918349344)
    channel = discord.utils.get(member.guild.channels, id=771081754038501376)
    if join_days < 10:
        await channel.send(f'{role.mention} {member} is suspicious of being an alt, he joined {join_days} after creating his account. Pls keep an eye on him')

@client.event
async def on_member_remove(member):
    pass

我该如何解决这个问题?

python pycharm discord discord.py
1个回答
24
投票

错误会告诉您具体该怎么做。

  1. 转到https://discord.com/developers/applications
  2. 导航至您的应用程序
  3. 转到
    Bot
    部分
  4. 向下滚动并启用
    SERVER MEMBERS INTENT
© www.soinside.com 2019 - 2024. All rights reserved.