Code
import os, discord, requests, jsonfrom base64 import b64decodefrom discord.ext import commands
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")client = commands.Bot(command_prefix="!", intents= discord.Intents.all())
client.eventasync def on_message(message): print("message was: " + message.content) if message.author == client.user: return if message.content == "!radar": url = "https://radar.weather.gov/ridge/standard/CONUS_0.gif" r = requests.get(url, allow_redirects=True) response_parsed = json.loads(r) thumbnail_bytes = b64decode(response_parsed<"thumbnail
Base64">) await message.channel.send(file=thumbnail_bytes)
client.command()async def ng(ctx): await ctx.send("Pong!")def start(): client.run(DISCORD_TOKEN)Error
Traceback (most recent call last): file "/home/runner/Stormy
Bot/venv/lib/python3.10 /site-packages/discord/client.py", tine 441, in _r un_event await coro(*args, **kwargs) tệp tin "/home/runner/Stormy
Bot/bot.py", tine 21, i n on_message response_parsed = json.loads(r) file "inix/store/hd4cc9rh83j291r5539hkf6qd8lgiik b-python3-3.10.8/lib/python3.10/json/__init__.py", tine 339, in loads raise Type
Error(f"the JSON object must be str, bytes or bytearray, "Type
Error: the JSON object must be str, bytes or bytearray, not Response
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
With the line r = requests.get(url, allow_redirects=True) you are getting a Response object, not a JSON.
Bạn đang xem: Sticker cdn url does not open for gif format · issue #6675
try response_parsed = json.loads(r.json()), it should solve the problem.
That URL doesn"t return JSON at all, it"s just a GIF (as the file extension suggests). You can"t parse/load it as JSON, and you can"t get its thumbnail
Base64 field. Because it"s a GIF. & not a JSON file.
IT IS POSSIBLE
Here’s how ~
We can fetch the gif và save it to lớn the directory (will overwrite every time) with urllib.
Then we simply post an image with the bot as usual. (Found my basis at Geeksfor
Geeks)
Here is the final code:
import os, discord, requests, json, urllib.requestfrom base64 import b64decodefrom discord.ext import commands
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")client = commands.Bot(command_prefix="!", intents= discord.Intents.all())
client.eventasync def on_message(message): print("message was: " + message.content) if message.author == client.user: return if message.content == "!radar": urllib.request.urlretrieve("https://radar.weather.gov/ridge/standard/CONUS_loop.gif", "rdr.gif") await message.channel.send(file=discord.File("rdr.gif"))
Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more
Thanks for contributing an answer to lớn Stack Overflow!
But avoid …
Asking for help, clarification, or responding to lớn other answers.Making statements based on opinion; back them up with references or personal experience.Xem thêm: Hướng dẫn cách làm mờ sẹo tại nhà, top 5 cách trị sẹo tại nhà hiệu quả
To learn more, see our tips on writing great answers.
Post Your Answer Discard
By clicking “Post Your Answer”, you agree to our terms of service và acknowledge you have read our privacy policy.
Company cookie-settings#toggle" class="s-btn s-btn__link py4 js-gps-track -link" data-gps-track="footer.click( location: 2, link: 38 )" data-consent-popup-loader="footer">Cookie Settings
Site kiến thiết / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA. Rev2024.4.12.7646 Include my e-mail address so I can be contacted
You signed in with another tab or window. Reload to lớn refresh your session. You signed out in another tab or window. Reload lớn refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
Have a question about this project? Sign up for a không tính tiền Git
Hub trương mục to open an issue and tương tác its maintainers và the community.
Hub
By clicking “Sign up for Git
Hub”, you agree khổng lồ our terms of service & privacy statement. We’ll occasionally send you trương mục related emails.
Already on Git
Hub? Sign in to lớn your account
DescriptionThe following error occurs when opening the CDN URL of a GIF sticker (custom vps sticker):No Example URL:https://cdn.discordapp.com/stickers/id*.gif If it was a PNG Sticker, the URL will work normally:https://cdn.discordapp.com/stickers/id*.png * I have omitted the actual ID in this report. Steps to ReproduceCreate a GIF sticker in a Discord serverGrab its IDTry to open the CDN URL: https://cdn.discordapp.com/stickers/sticker_id_here.gif Expected BehaviorCDN URL should return the actual image, not an error. Current BehaviorNo Screenshots/VideosNo response Client & System InformationLatest Firefox và Chrome on Windows 10. Latest Discord client on game android (Image not rendered) |
jkcailteux commented Feb 20, 2024 Copy liên kết |