M
M
MIKHAN_GO2021-10-03 15:07:43
Python
MIKHAN_GO, 2021-10-03 15:07:43

Why doesn't the bot code work on the server?

I wrote a code that sends a picture with user data to the chat on the discord server. Everything works stably on my computer, but when I transfer the code to a remote linux server, the picture stops being sent to the chat

@client.command(aliases=["card", "usercard", "user_card"])
async def card_user(ctx):
    await ctx.send(":Sin:")
    # await ctx.channel.purge(limit=1)

    img = Image.new('RGBA', (400, 200), '#232529')
    url = str(ctx.author.avatar_url)[:-10]

    response = requests.get(url, stream=True)
    response = Image.open(io.BytesIO(response.content))
    response = response.convert('RGBA')
    response = response.resize((100, 100), Image.ANTIALIAS)

    img.paste(response, (15, 15, 115, 115))

    idraw = ImageDraw.Draw(img)

    name = ctx.author.name
    tag = ctx.author.discriminator
    # user = [r.name for r in guild.roles]
    # highest = discord.utils.find(lambda role: role in my_roles, reversed(ctx.author.roles))

    headline = ImageFont.truetype('arial.ttf', size=20)
    undertext = ImageFont.truetype('arial.ttf', size=12)

    idraw.text((145, 15), f'{name}#{tag}', font=headline)
    idraw.text((145, 50), f'ID: {ctx.author.id}', font=undertext)
    path = os.getcwd()

    img.save(f'{path}\\user_card.png')

    await ctx.send(file=discord.File(fp=f'{path}\\user_card.png'))

    os.remove(f'{path}\\user_card.png')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-10-03
@Vindicar

> ImageFont.truetype('arial.ttf', size=20) Is
the font file present and available to the bot?
> f'{path}\\user_card.png'
os.path.join() and pathlib for whom? Under Linux, the directory separator is not \ but /.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question