AttributeError: 'NoneType' object has no attribute 'channels'
本问题已经有最佳答案,请猛点这里访问。
嗨,我的discord bot模块有问题。我得到了
以下是我的工作内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | from discord.ext import commands from discord.utils import get import logging as log from datetime import datetime,timedelta import discord import os from .utils import checks from run import UKGBot import asyncio class Pinner(): """Pins messages to a specific channel.""" def __init__(self, bot: UKGBot): self.bot = bot async def on_message(self, message): """Listen for message then pin it""" try: guild = message.guild channel = get(message.guild.channels, name="gtky") pins = await message.channel.pins() if message.channel == channel and message.type != discord.MessageType.pins_add: if len(pins) == 20: await message.unpin(pins[-1]) await asyncio.sleep(3) await message.pin() except discord.Forbidden: print("No permissions to do that!") def setup(bot): """Setup function""" to_add = Pinner(bot) bot.add_listener(to_add.on_message, 'on_message') bot.add_cog(to_add) |
您试图访问某个对象的
根据您的代码,您唯一引用通道的地方是
这是因为
如果您的bot发送或接收任何私有消息,这些消息将具有