R
R
RieldaBot2021-09-15 22:11:10
Python
RieldaBot, 2021-09-15 22:11:10

Discord.py, how to make attachments save and send an image to another channel?

there is a code:

import discord
from discord.ext import commands
import uuid

bot = commands.Bot(command_prefix="*")


@bot.command(pass_context=True)
async def grole(ctx, arg):
    username = ctx.message.author
    channel = bot.get_channel("") #указываю ид канала на который отправляю текст
    await channel.send(arg)
    await channel.send(username)
    await channel.send('-----------------------------')


How can I make the *grole command with the text that the user sends send the image that the user sends, but at the same time that the image is not saved to my PC?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FOUREX, 2021-09-18
@RieldaBot

@bot.command()
async def grole(ctx):
  import io

  username = ctx.author
  channel = bot.get_channel(id=111111111111111111) 
  for attach in ctx.message.attachments:
    imgn = attach.filename
    img = io.BytesIO(await attach.read())

  await channel.send(file = discord.File(img, imgn))

Yes, and in new versions, the pass context does not seem to be needed.
And I did not understand the purpose of the second argument, so I removed it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question