Aim of this is to try get a local image saved on your computer sent to a discord channel via a bot
# Create an Intents object with the `messages` attribute set to True
intents = discord.Intents(messages=True)
# Create the client with the specified intents
client = discord.Client(intents=intents)
@client.event
async def on_ready():
# When the bot is ready, send the image to the specified channel
channel = client.get_channel(CHANNEL_ID)
with open(r"file path", 'rb') as f:
file = discord.File(f)
await channel.send(file=file)
client.run(TOKEN)
Traceback (most recent call last):
File "C:\Python\Python39\lib\site-packages\discord\client.py", line 409, in _run_event
await coro(*args, **kwargs)
File "path", line 39, in on_ready
await channel.send(file=file)
AttributeError: 'NoneType' object has no attribute 'send'
CodePudding user response:
The offical documentation for Discord.py says
Parameters: id (int) – The ID to search for.
Returns: The returned channel or
None
if not found.
This means that the ID supplied does not match any server, so most likely you mistyped it or accidentally modified it in code somewhere
CodePudding user response:
await channel.send(file=file)
AttributeError: 'NoneType' object has no attribute 'send'
So channel
is None
, so the error was caused by the following.
channel = client.get_channel(CHANNEL_ID)
I guess 99% that CHANNEL_ID
is a str
ing and not an int
eger...