1
votes
import os
import discord

import random
from prettytable import PrettyTable
from PIL import Image


client = discord.client()

    
@client.event
async def on_ready():
    print("We have logged in as {0.user}".format(client))
  

@client.event
async def on_message(message):
    if message.author == client.user:
        return


    if message.content.startswith("$picture"):
       
        await channel.send(file=discord.File("images.jpg"))
    


client.run(os.getenv('TOKEN'))

Hello this is my first time using stack overflow I apologize ahead of time if my post has some mistakes, so I was trying to have my discord upload a picture when entering a "$picture" in the chat box, but I get an red underline at the line that says await channel.send(file=discord.File("images.jpg")) Saying "undefined named 'channel'" I tried looking into it but couldnt find much. Any ideas? thank you.

1
This means your variable isn't defined anywhere. @GGberry has the correct solutionTaylor Cochran

1 Answers

1
votes

You need to do message.channel.send() and not channel.send().

So instead of

@client.event
async def on_message(message):
    if message.author == client.user:
        return


    if message.content.startswith("$picture"):
       
        await channel.send(file=discord.File("images.jpg"))

You can do

@client.event
async def on_message(message):
    if message.author == client.user:
        return


    if message.content.startswith("$picture"):
       
        await message.channel.send(file=discord.File("images.jpg"))