我在vsc中制作了一个不和谐的bot,它的工作原理非常好。我希望它可以联机运行而无需打开计算机。我将代码放在GitHub中,并将其连接到Heroku。当我索要图像时,一切都按预期进行。
当我执行!help时,它会弹出帮助菜单。但是当我做!png框时,什么也没发生。这是vsc中的代码,工作时(代码和图像位于同一文件夹中)
@client.command()
async def png(ctx, *, arg):
if(arg == 'box'):
await ctx.send(file=discord.File('box.png'))
我需要更改代码还是必须执行的操作?图像位于GitHub上的一个名为items的文件夹中,如何更改代码以使其正常工作。
(这也是我第一次使用GitHub和Heroku,所以可能会有一个我不知道的简单答案,而且我对编码也很陌生)
如果该图像在Heroku本地不可用,则可以从github发送该图像。如文档所示,您可以使用aiohttp发出HTTP请求,然后将io.BytesIO实例传递给File。确保您使用指向github上图像的直接URL。
import io
import aiohttp
@client.command()
async def png(ctx, *, arg):
if(arg == 'box'):
async with aiohttp.ClientSession() as session:
async with session.get("https://raw.githubusercontent.com/your_github_name/your_repo_name/master/items/box.png") as resp:
if resp.status != 200:
return await ctx.send('Could not download file...')
data = io.BytesIO(await resp.read())
await ctx.send(file=discord.File(data, 'box.png'))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句