简体   繁体   English

向 Discord 文本文件发出获取请求以获取文件内容

[英]Making a get request to a Discord text file to get the file contents

I am trying to get the contents of a text file through get requests however I am receiving a strange response with Greek letters and spaces between each character.我正在尝试通过获取请求获取文本文件的内容,但是我收到了一个奇怪的响应,其中包含希腊字母和每个字符之间的空格。

Link:关联:

https://cdn.discordapp.com/attachments/651144916944027658/717426226255495208/my_file.txt

Headers:标题:

Content-Type: text/plain

My text file contents:我的文本文件内容:

123.456.789

Response after doing the get request:执行获取请求后的响应:

ÿþ1 2 3 . 4 5 6 . 7 8 9

I'm not sure if there are some headers that I am missing but I can't seem to get this to work, I've tried in C# and Python and have received the same response each time.我不确定是否有一些我丢失的标题,但我似乎无法让它工作,我已经尝试过 C# 和 Python 并且每次都收到相同的响应。

If the file is being attached to a message, you'll be able to save() it:如果文件被附加到消息中,您将能够save()它:

@bot.command()
async def savefile(ctx):
    await ctx.message.attachments[0].save("my_file.txt")
    await ctx.send("Saved the file!")

You can also add checks for certain file extensions and such.您还可以添加对某些文件扩展名等的检查。
If you want to save it with the same file name it was uploaded with:如果您想使用上传时使用的相同文件名保存它:

@bot.command()
async def savefile(ctx):
    attachment = ctx.message.attachments[0]
    # this will save it with the correct file extension
    await attachment.save(attachment.filename) 
    await ctx.send("Saved the file!")

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM