【发布时间】:2019-12-18 21:38:45
【问题描述】:
我制作了一个机器人,它从我的下载文件夹中名为willy 的文件夹中随机发送一张威尔史密斯的照片。我没有实现随机部分,但我试图让机器人在名为0aPw0J4.png 的willy 文件夹中发送图像。我只希望脚本能够找到图像并上传它。目前的错误是即使我尝试列出从我的C: 驱动器开始的目录,python 也找不到该目录,但这没有用,所以我删除了它。
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = "!_")
@client.event
async def on_ready():
print('bots online')
@client.command()
async def will(ctx):
await ctx.send('will')
@client.event
async def on_message(message):
if message.content.startswith('!_will'):
embed = discord.Embed(title="A photo of Will Smith", description="Here he is", color=0x00ff00)
embed.add_field(name="Field2", value="hi2", inline=False)
embed.set_image(url="https://discordapp.com/assets/e4923594e694a21542a489471ecffa50.svg")
await message.channel.send(embed=embed)
await client.send_file(channel, "0aPw0J4.png", content="...", filename="...")
@client.event
async def on_message(message):
if message.content.startswith('!willy'):
file = discord.File("0aPw0J4.png", filename="0aPw0J4.png")
await message.channel.send("0aPw0J4.png", file=file)
client.run('my bot token hidden')
我尝试更改我的默认目录,但也没有用。
【问题讨论】:
-
请分享完整的错误信息。
-
你定义了两个同名的函数
-
@AlexanderCécile FileNotFoundError: [Errno 2] 没有这样的文件或目录:'0aPw0J4.png'
-
@aws_apprentice 是底部的两个
client.events 吗? -
是的,您是否尝试过提供文件的完整路径?
标签: python discord.py