我在这里要做的是获取斜杠命令附件的url或原始文件。作为一个没有经验的人,我遇到了一些问题。在discord方面,它获取选项类型并显示附件提示。但是,当用户发送带有附件的命令时,我得到的只是一些数字的字符串(966169863519350854)。我不知道是我遗漏了什么还是做错了。下面是我的代码和在控制台中打印的内容。
import discord
from discord.ext import commands
from discord_slash import SlashCommand, SlashContext
from discord_slash.utils.manage_commands import create_choice, create_option
client = commands.Bot(command_prefix="!")
slash = SlashCommand(client, sync_commands=True)
@slash.slash(
name="identify",
description="Identify Image",
guild_ids=[805487639443931136],
options=[
create_option(
name="image",
description="Attach an Image",
required=True,
option_type=11, #Attachment
)
]
)
async def _identify(ctx:SlashContext, image):
print(type(image))
print(image)
client.run('')
控制台输出:
<class 'str'>
966169863519350854
谢谢!
我最终切换到interaction .py。因为附件是一个类,我做了image.url
,它得到了我说的附件的url。