How do I use client.send_file discord.py

2019-09-15 06:02发布

问题:

@my_bot.command()
async def memes():
    await client.send_file(discord.Object(id='321332957690331138'),'1.jpg')

I used that and I got error code 401 aka Unauthorized

my_bot.run(TOKEN)

I'm using that to login All my other commands work and do not output this error. -I'm quite new to this website so I may have done something wrong-

回答1:

Your issue is that you need to pass a proper destination (channel in server) as the first parameter. To get the server object from a server ID you can use:

server = client.get_server('321332957690331138')

and to get the default channel of that server you can use:

server.default_channel

So to sum it up you now have:

await client.send_file(client.get_server('321332957690331138').default_channel, '1.jpg')

Hope I helped!