how do i send an image with discord.py #6515
-
how do i send an image with discord.py? i have tryed many things but i get this error import discord
from discord import *
from discord.ext import commands
import requests
import sys
import subprocess
import os
import time
from time import sleep
from os import system
url = 'image url' #i have an image url here
r = requests.get(url, allow_redirects=True)
open('savage.jpg', 'wb').write(r.content)
bot = commands.Bot(command_prefix='>')
@bot.command()
async def ping(ctx):
channel = message.channel
my_files = [
discord.File('savage.jpg'),
]
await channel.send(files=my_files)
@bot.command()
async def image():
await channel.send(file=discord.File('D:\coding\python project\discord.py\funny.jpg'))
bot.run('token') #i have token in here errors:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
In the faq section of the documentation there is an example of how to do this. You will find this here. Also, in your command called |
Beta Was this translation helpful? Give feedback.
-
MhmCats answered the question, but I have noticed you have |
Beta Was this translation helpful? Give feedback.
In the faq section of the documentation there is an example of how to do this. You will find this here.
Also, in your command called
image
you are missing thectx
parameter that commands require. From thectx
parameter you can get the message and the channel because at the moment I am not sure where you are getting thechannel
in line 3 of theimage
command from and also the message in line 3 of theping
command.