python “before.channel“和“after.channel“在on_voice_state_update()函数中被标记为无类型

wztqucjr  于 12个月前  发布在  Python
关注(0)|答案(1)|浏览(78)

当用户连接到一个专用的语音通道(ID为1191737629281107978)时,该功能必须创建一个克隆的语音通道,当没有人时,该功能将删除该通道。

@client.event
async def on_voice_state_update(member, before, after):
    possible_channel_name = f'new {member}`s channel'
    if after.channel.id == 1191737629281107978:
        temp_channel = await after.channel.clone(name=possible_channel_name)
        await member.move_to(temp_channel)
    if before.channel.name == possible_channel_name and len(before.channel.members) == 0:
        await before.channel.delete()

字符串
它特别的作品,它使一个新的渠道,但不删除它在年底,并与2错误:

line 58, in on_voice_state_update
    if after.channel.id == 1191737629281107978:
       ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'id'


line 61, in on_voice_state_update
    if before.channel.name == possible_channel_name and len(before.channel.members) == 0:
       ^^^^^^^^^^^^^^^^^^^


我查了查,意图可能有问题,但它有

intents = discord.Intents.all()
intents.members = True

client = commands.Bot(intents=intents, command_prefix="/")


和一切可以打开不和谐的发展网站(已注册的网关意图太).此外,在此之后,我recconnected机器人到服务器几次.我使用discord.py和这些bibliotecks:

import discord
from discord.ext import commands
from datetime import datetime
from PIL import Image, ImageDraw
import asyncio
import configure
import sqlite3
import requests
import io

bnl4lu3b

bnl4lu3b1#

您可以添加检查以确保before.channelafter.channel不是None

@client.event
async def on_voice_state_update(member, before, after):
    possible_channel_name = f'new {member}`s channel'
    if after.channel and after.channel.id == 1191737629281107978:
        temp_channel = await after.channel.clone(name=possible_channel_name)
        await member.move_to(temp_channel)
    if before.channel and before.channel.name == possible_channel_name and len(before.channel.members) == 0:
        await before.channel.delete()

字符串

相关问题