![](/img/trans.png)
[英]why am i getting "AttributeError: 'NoneType' object has no attribute 'get' "
[英]Why am I getting a `AttributeError: 'NoneType' object has no attribute 'send'` Error
它一次又一次地工作,我试图从一个工作和加载正常的.env文件加载我的日志通道,但是当我 go 向我的日志通道发送日志消息时,我得到AttributeError: 'NoneType' object has no attribute 'send'
ID 是正确的,我已明确授予机器人在该频道中发送的权限,但错误仍然存在。
# Load Bot token
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
CHANNEL = os.getenv('LOG_CHANNEL')
# Set Bot command prefix
prefix = 'Q!'
bot = commands.Bot(command_prefix=prefix)
channel = bot.get_channel(CHANNEL)
.env 文件具有LOG_CHANNEL = 512123500123652096
并正确加载它,将CHANNEL
标记为 int() 也无济于事
这是机器人开机时做的第一件事
这是我记录的地方,它在最后的命令中
# Log command
command = discord.Embed(description=f"File unzipped in {ctx.channel.mention}", color=0x4040EC).set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
command.add_field(name="File", value=f'{filename}')
command.timestamp = ctx.message.created_at
await channel.send(embed=command)
检索频道的正确方法是使用:
bot.get_channel(id)
如果您从文件中读取通道 id,它可能会将其作为字符串,您需要将其转换为 int:
channel = bot.get_channel(int(CHANNEL))
如果您的CHANNEL
包含一些额外的空格(可能在末尾有一个空格), get_channel
也可能返回None
。 确保仔细检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.