-3

For some reason, I keep getting this error message, I can't understand it because everything I've seen online seems like my code should be working:

import discord #imports packages
import random
client = discord.Client(intents=discord.Intents.default())
def get_quote():
        x = 0
        f = open(r"C:\Users\natem\OneDrive\Documents\phil_quotes.txt", "r")
        content = f.readlines()
        for line in f:
                x += 1
        quote = (content[random.randint(0,x)])
        f.close
        return quote
@client.event
async def on_ready():
        jeneral_channel = client.get_channel(Channel ID)
        gospel = get_quote()
        await jeneral_channel.send(message)
client.run("TOKEN")
  • 1
    FYI, `f.close` does nothing if you don’t *call* it. – deceze Aug 24 '22 at 16:46
  • 1
    Does this answer your question? [Why do I get AttributeError: 'NoneType' object has no attribute 'something'?](https://stackoverflow.com/questions/8949252/why-do-i-get-attributeerror-nonetype-object-has-no-attribute-something) – RoadieRich Aug 24 '22 at 16:53

1 Answers1

0

What's happening is jeneral_channel = client.get_channel(...) is resulting in jeneral_channel being a None object because client.get_channel is returning nothing - aka a None object.

Which means this is a problem with your attempt to get the channel not being properly functioning, meaning you're either doing it wrong or your access for your client doesn't have access to the channel ID/channel/information.

I would re-consult the API for the Discord library you are using, make sure you set up your user authentication and application authentication (bot auth!) properly, the bot/client in question is joined to your Discord server and channel properly, and that you've actually provided proper credentials and a proper ChannelID value for the system that your client has access to in your code.

(this was previously a comment but I've made it an answer now)

Thomas Ward
  • 2,714
  • 7
  • 36
  • 51