AttributeError: NoneType object has no attribute channels [duplicate]

2024/11/16 6:29:55

Hi I'm having an issue with a module for my Discord bot. I'm getting AttributeError: 'NoneType' object has no attribute 'channels' I'm not sure way it's throwing out this error:

Here is what I'm working with:

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 UKGBotimport asyncioclass Pinner():"""Pins messages to a specific channel."""def __init__(self, bot: UKGBot):self.bot = botasync def on_message(self, message):"""Listen for message then pin it"""try:guild = message.guildchannel = 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)
Answer

You are trying to access the channels property of some object, but that object is None == Null in other languages.

From your code the only place you reference channels is message.guild.channels, in the channel = get(message.guild.channels, name="gtky") line, so the guild property of the message object is None

https://en.xdnf.cn/q/119559.html

Related Q&A

How to get a specific value from a html header

Im using selenium to get request headers from a web page, the problem is that it prints out all request headers sent and i want to get only one value from one of them. I dont know how to do it and i ha…

How to use windows as raspberry pi and connect the windows with another raspberry pi [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 4…

Python : Return the missing weekdays dates and assign rate next to missing date

Dates rates 7/26/2019 1.04 7/30/2019 1.0116 7/31/2019 1.005 8/1/2019 1.035 8/2/2019 1.01 8/6/2019 0.9886 8/7/2019 1.0048 8/8/2019 0.97 8/9/2019 0.9659 8/12/2019 0.965In …

How do I use a list or set as keys in file renaming

Is something like this possible? Id like to use a dictionary or set as the key for my file renamer. I have a lot of key words that id like to filter out of the file names but the only way iv found to …

How to change Python comment font style in the latest VS Code? [duplicate]

This question already has an answer here:How to change the font-style of code comments in vscode?(1 answer)Closed 6 months ago.Seems like with the latest VS Code update, all the comment font style has…

How to crop an image based on a complex criteria?

I have a set of similar images like the one below. I want to keep the portion of the image that is within the top red irregular rectangle (green arrows represent the space that I want to keep; anything…

Getting current video tag URL with selenium

Im trying to get the current html5 video tag URL using selenium (with python bindings):from selenium import webdriverdriver = webdriver.Chrome() driver.get(https://www.youtube.com/watch?v=9x6YclsLHN0)…

How to determine if two rows are identical (similar) if row 2 contains part of the info from row 1?

Hope you are having a good day. I am currently working with an extremely dirty dataframe containing First Name, Last Name, and Middle Name. One the issues that I am trying to resolve looks like below:F…

Cartopy fancy box

Hello I have been trying to plot data in a Orthographic projection. The data is plotted but I want the box to follow the data limits. Like in this example I am sharing form M_map[enter image descriptio…

discord.py - No DM sent to the user

I am making a discord.Client. I have a DM command that sends a DM to a specific user, but no message is sent to the user when the command is run, but a message is sent on the Context.channel. Here is m…