Discord py - 'id': target.id AttributeError: 'NoneType' object has no attribute 'id' - in version 1.5.1

Discord py - 'id': target.id AttributeError: 'NoneType' object has no attribute 'id' - in version 1.5.1

大家好,我有个大问题...

在我的办公室,我使用 discord.py-1.4.1 和此代码:

import discord
import asyncio, os, random
import urllib.parse, urllib.request, re
from discord.utils import get
from discord.ext import commands
from discord import NotFound
from discord.utils import get

client = commands.Bot(command_prefix="!")
client.remove_command("help")
guild = discord.Guild

@client.event
async def on_ready():
    print("Skipzz-Test-Bot is now online")

@client.event
async def on_raw_reaction_add(payload):
    guild_id = payload.guild_id
    guild = client.get_guild(guild_id)
    user = payload.user_id
    emoji = payload.emoji.name
    category = guild.get_channel(766608102081822730)
    
    if user == 762903825866424320:
        return
    
    if emoji == "":
        member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members)
        support_role = guild.get_role(765108248583733248)
        overwrites = {
            guild.default_role: discord.PermissionOverwrite(read_messages=False),
            member: discord.PermissionOverwrite(read_messages=True, send_messages=True),
            support_role: discord.PermissionOverwrite(read_messages=True, send_messages=True)
        }
        ticket_nr = random.randint(100,999)
        await category.create_text_channel(f'ticket-{ticket_nr}', overwrites=overwrites)

@client.command()
@commands.has_permissions(administrator=True)
async def reaction(ctx):
    msg = await ctx.send("This is a test for a reaction!")
    await msg.add_reaction("")

client.run(MY_TOKEN)

一切正常 - 如果用户点击表情符号 - 将创建一个频道 - 只有用户和支持角色可以访问此频道。

但在家里我使用的是最新版本的 discord.py-1.5.1

我在同一代码上遇到错误

'id': target.id AttributeError: 'NoneType' object has no attribute 'id'

为什么?????

他们改变了什么重要的东西吗?如果是,我该如何编辑我的代码?

感谢您的帮助:)

在discord.py(1.5.x)的新版本中,有一些关于Intents的更新。意图就像权限,您需要将其定义为获取频道、成员等。您必须在定义 client = discord.Bot(prefix='!').

之前定义它
import discord
import asyncio, os, random
import urllib.parse, urllib.request, re
from discord.utils import get
from discord.ext import commands
from discord import NotFound
from discord.utils import get

intents = discord.Intents().all()
client = commands.Bot(command_prefix="!", intents=intents)

关于Intents的更多信息,您可以查看API References