0

so I checked all over in stack overflow for answers and nothing.

Im trying to make it that when the bot fires up it will send a message in a channel, I have alr checked if the bot can see and talk in the channel and they can.

My code:

import discord
from discord.ext import commands
from datetime import datetime

intents = discord.Intents().all()
bot = commands.Bot(command_prefix="!", intents=intents, case_insensitive=True)
client = discord.Client(intents=intents)


@bot.event
async def on_ready():
  print('We have logged in as {0.user}'.format(bot))
  current_time = datetime.now().strftime("%H:%M:%S")
  channel = bot.get_channel('1069075658979954700')
  embed = discord.Embed(title="GAH Verification",
                        description="I have awoken",
                        color=discord.Color.green())
  embed.set_footer(text=current_time)
  await channel.send('Hi')


bot.run(
  "MTA2OTI2NDQ0MTQwMjcyODU3MQ.GV353u.XXagXFsp3Ax4vRxvt3y5s6P9FPPDrOeMh2M7jI")

Error:

Traceback (most recent call last):
  File "/home/runner/GAH-Bot/venv/lib/python3.10/site-packages/discord/client.py", line 409, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 19, in on_ready
    await channel.send('Hi')
AttributeError: 'NoneType' object has no attribute 'send'
  • 2
    The error seems to suggest that `bot.get_channel()` returned `None`. You've verified the channel is infact correct? – B Remmelzwaal Jan 29 '23 at 17:02
  • Yes I have I checked it over multiple times – JadtruGaming Jan 29 '23 at 17:04
  • 3
    Found [this](https://stackoverflow.com/a/73601447/17200348) with a quick search, make sure the channel ID isn't in quotes. – B Remmelzwaal Jan 29 '23 at 17:05
  • No problem, just remember to Google your issues and most likely it has been encountered before :) – B Remmelzwaal Jan 29 '23 at 17:08
  • 2
    What does the doc for `bot.channel` say? You should have error detection code after a call that can fail to catch errors early. – tdelaney Jan 29 '23 at 17:10
  • 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) – Ulrich Eckhardt Jan 29 '23 at 17:53
  • Does this answer your question? [dicord.py: get\_channel() returns None](https://stackoverflow.com/questions/65789837/dicord-py-get-channel-returns-none) – The Amateur Coder Jan 29 '23 at 19:27

1 Answers1

0

currently bot.get_channel() returns None,

either because it dont get it because 1069075658979954700 is in quotes

you should try using:

bot.get_channel(1069075658979954700)

and check if the bot has access to the channel

if this won't work you can always try to get the channel via the server this should work 100% because maybe the channel is not loaded to the cache directly idk

server = bot.get_guild(1234) # server id here
channel = await server.fetch_channel(12345) # channel id here
raphiel
  • 711
  • 2
  • 9
  • 24