discord.py一次与for循环一起发送多个文件
因此,我正在尝试制作一个不和谐的
机器发送图像
import discord
import os
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$doit'):
await message.channel.send(file=discord.File("./images/*"))
client.run("OT*****************************************")
So I'm trying to make a discord bot that when I write $doit
it sends all the files in the image folder but I would like it to do it one by one
So basically make a for loop and send the images
import discord
import os
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$doit'):
await message.channel.send(file=discord.File("./images/*"))
client.run("OT*****************************************")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我的代码正常:
我做了什么:
$ doit
命令,因为它是命令,而不是事件。我将您的前缀定义为$
和doit
为命令/函数。OS
库列出了目录中的所有文件,您可以将其定义为dir_path
actible,然后将文件名添加到res
list 。,将每个文件从
res
列表发送为单独的消息。它对我来说很好。
如果您有任何疑问,请随时提出。 :)
ps现在它将目录中的每个文件发送,无论是否是图像。您可以将其限制为仅使用简单
的图像,如果
条件并指定文件的扩展(.jpg
,.png
等) 。Here's my code that works fine:
What I've done:
$doit
a command, since it's rather a command, not an event. I've defined your prefix as$
anddoit
as the command/function.os
library to list all the files in the directory you can define asdir_path
variable and add the files names to theres
list.for
loop just as you said to send every file fromres
list as a separate message.It worked fine for me.
If you have any questions, do not hesitate to ask. :)
P.S. Now it sends every file in a directory, no matter if it is an image or not. You can limit it to just images using a simple
if
condition and specify the extensions of the files (.jpg
,.png
, etc.).