Python Discord.py';非类型';对象没有属性';发送';

Python Discord.py';非类型';对象没有属性';发送';,python,discord,discord.py,Python,Discord,Discord.py,当我尝试运行该命令时,总是会收到以下错误消息:Discord.py“NoneType”对象没有属性“send” import os import json import discord from discord.ext import commands def get_channel(client, message): with open('./data/welcome.json', 'r') as f: tchann = json.load(f) return

当我尝试运行该命令时,总是会收到以下错误消息:Discord.py“NoneType”对象没有属性“send”

import os
import json
import discord
from discord.ext import commands

def get_channel(client, message):
    with open('./data/welcome.json', 'r') as f:
        tchann = json.load(f)
    return tchann[str(message.guild.id)]

class welcome(commands.Cog):

    def __init__(self, client):
        self.client = client

    # Events
    @commands.Cog.listener()
    async def on_ready(self):
        print('Welcome script loading.')

    @commands.Cog.listener()
    async def on_member_join(self, member):
        embed=discord.Embed(title="Yoshino",
            url="http://animeex.nhely.hu/",
            description=f"asd1.",
            color=0x29FF94)

        channel = self.client.get_channel(id=get_channel)

        await channel.send(embed=embed)

    @commands.command()
    async def welcome(self, ctx, channel):
        with open('./data/welcome.json', 'r') as f:
            tchann = json.load(f)

        tchann[str(ctx.guild.id)] = channel

        with open('./data/welcome.json', 'w') as f:
            json.dump(tchann, f, indent=4)

        await ctx.send(f'Channel set: {channel}')

def setup(client):
    client.add_cog(welcome(client))
错误代码:

文件 “C:\Users\NexaHn\AppData\Local\Programs\Python\Python39\lib\site packages\discord\client.py”, 第343行,运行事件中 等待coro(*args,**kwargs)文件“K:\Discord BOT\PythonX\cogs\welcome.py”,第30行,在on_member_join中 wait channel.send(embed=embed)AttributeError:'NoneType'对象没有属性'send'

import os
import json
import discord
from discord.ext import commands

def get_channel(client, message):
    with open('./data/welcome.json', 'r') as f:
        tchann = json.load(f)
    return tchann[str(message.guild.id)]

class welcome(commands.Cog):

    def __init__(self, client):
        self.client = client

    # Events
    @commands.Cog.listener()
    async def on_ready(self):
        print('Welcome script loading.')

    @commands.Cog.listener()
    async def on_member_join(self, member):
        embed=discord.Embed(title="Yoshino",
            url="http://animeex.nhely.hu/",
            description=f"asd1.",
            color=0x29FF94)

        channel = self.client.get_channel(id=get_channel)

        await channel.send(embed=embed)

    @commands.command()
    async def welcome(self, ctx, channel):
        with open('./data/welcome.json', 'r') as f:
            tchann = json.load(f)

        tchann[str(ctx.guild.id)] = channel

        with open('./data/welcome.json', 'w') as f:
            json.dump(tchann, f, indent=4)

        await ctx.send(f'Channel set: {channel}')

def setup(client):
    client.add_cog(welcome(client))

该错误表示变量
通道
为非类型或
。这可能意味着没有id为
get\u channel
的频道。您可能希望运行函数
get\u channel
,而不是将其作为id

def get_channel(client, message):
    with open('./data/welcome.json', 'r') as f:
        tchann = json.load(f)
    return tchann[str(message.guild.id)]

channel = self.client.get_channel(id=get_channel)
get\u channel
是一种方法。它需要一个
int
。见:


channel=self.client.get_channel(id=123456789)
将是有效的(如果id
123456789
存在)。

感谢您帮助我解决问题。