python - 如何让机器人在 discord.py 中发布剧透图像?
问题描述
我在一两个月前开始使用 discord.py,所以这可能真的很简单。我的代码是:
attachment_url = ctx.message.attachments[0].url
await archiver.send(attachment_url)
“存档”是我发送它的频道。如何使用扰流标签发送它?我浏览了文档,但它们没有帮助。
谢谢。
解决方案
为了让您上传图片作为剧透,您需要添加SPOILER_
到图片名称的开头,您可以这样做:
file = ctx.message.attachments[0]
file.filename = f"SPOILER_{file.filename}"
spoiler = await file.to_file()
await archiver.send(file=spoiler)
推荐阅读
- javascript - 在输入表中添加或删除行以及一些可用的 Jinja
- python - 如何从 tkcalendar.Calendar 中的 get_date 方法获取 4 位数年份或日期/日期时间对象的日期?
- reactjs - 如何在 React 中渲染动态表格
- java - 将 ReadableByteChannel 保存为 PNG
- tiptap - 提示如何在 Shift-Enter 上创建段落 (p),而不是 br?
- java - Java 8流按多个属性和总和分组
- apache-spark - Pyspark 计数空值列值特定
- sql - 在 CREATE VIEW 内的 WITH...AS 中使用多个表表达式时出现“找不到对象”错误
- android - Java 函数 .asBytes() 的 Kotlin 等价物是什么?
- json - 在 VS2019 中获取“找不到方法:'Boolean Newtonsoft.Json.Schema.SchemaExtensions.IsValid”