我是編碼新手,我想問是否有人知道是否可以在 python 中使用 hikari 從檔案夾發送(隨機)影像,并可以幫助我編輯我的代碼
@lightbulb.command('img', 'image')
@lightbulb.implements(lightbulb.PrefixCommand)
async def image(ctx):
f = hikari.File('C:/Users/User/Desktop/folder/file.jpg')
await ctx.respond(f)
uj5u.com熱心網友回復:
這可以作業:
images = os.path.join(os.getcwd(), "images")
def select_random_image_path():
return os.path.join(images, random.choice(os.listdir(images)))
@lightbulb.command('img', 'image')
@lightbulb.implements(lightbulb.PrefixCommand)
async def image(ctx):
f = hikari.File(select_random_image_path())
await ctx.respond(f)
如果您的檔案結構如下所示:
| main.py
---images
| 73doCML.jpg
| BcAyMo7.jpg
| eRcYeHL.jpg
| HSlG1Gl.jpg
| IDgfXn6.jpg
| ljFuj1z.jpg
| MmBXwZN.jpg
| N0udyAV.jpg
| xenAlf8.png
| yc1kX4A.jpg
| ZJubdTU.jpg
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/453157.html
標籤:python-3.x 不和谐
