我要说的是,我在python方面没有任何经验。我正在尝试为私有Discord服务器创建一个bot,该服务器在键入“$gimme”后从ftp服务器(根目录)发布一个随机图像(.jpg)#文件名是随机的
我找了几个小时想找到一个解决办法,但我总是被一些事情卡住。我无法理解ftp和discord的语法,因为我对python的了解几乎不存在,无论我如何搜索答案,我都无法理解
这真的是我最后的选择,我没有别的地方可找了。我希望比我多一点知识的人能帮助我
多谢各位
import os
import requests
import ftplib
from ftplib import FTP
import random
client = discord.Client()
ftp = FTP()
ftp.connect(os.getenv('BOP_IP'), 2021)
ftp.login(os.getenv('BOP_UN'), os.getenv('BOP_PW'))
#path='/'
@client.event
async def on_ready():
print('We have logged in as {0.user}'
.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$gimme'):
await message.channel.send(#######)
client.run(os.getenv('TOKEN'))
@axelinux
非常感谢你花这么多时间来帮助我
在服务器上运行“$gimme”时出现以下错误
@axelinux
再次谢谢你
在discord中键入“$gimme”后,您发送给我的修订代码返回了以下内容:
我已经做了一些搜索,我想我现在已经成功了:
我所要做的就是将行更改为:ftp.retrbinary('RETR{0}'。format(random_file_name),open(random_file_name,'wb')。write)
非常感谢你的帮助。如果没有你,它就无法工作:)
使用回调方法编辑
我知道python和FTP不是discord,但通过查看文档,我发现了如何在discord中发送文件。我编写了以下代码(未经测试)。我添加了一个从FTP服务器随机获取文件的函数,并在on_message函数中调用该函数
要优化:
相关问题 更多 >
编程相关推荐