如何在 discordpy 的选项中输入?
How do I get input in an option in discordpy?
我正在为机器人编写此命令,但我不确定如何在选项后获取文本,例如:
/userinfo name: Hatsune Miku
最后打印出 hatsune miku
.
如果您使用的是 discord-interactions,您可以这样做:
齿轮
import discord
from discord.ext import commands
from discord_slash import cog_ext, SlashContext
from discord_slash.utils.manage_commands import create_option
class Slash(commands.Cog):
def __init__(self, client):
self.client = client
@cog_ext.cog_slash(name='userinfo', description="get user info", options=[create_option(name="name", description="Name", option_type=3, required=True)])
async def _userinfo(self, ctx, name):
await ctx.send(name)
在main.py
from discord_slash import SlashCommand
client = commands.Bot(...)
slash = SlashCommand(client, sync_commands=True)
我正在为机器人编写此命令,但我不确定如何在选项后获取文本,例如:
/userinfo name: Hatsune Miku
最后打印出 hatsune miku
.
如果您使用的是 discord-interactions,您可以这样做:
齿轮
import discord
from discord.ext import commands
from discord_slash import cog_ext, SlashContext
from discord_slash.utils.manage_commands import create_option
class Slash(commands.Cog):
def __init__(self, client):
self.client = client
@cog_ext.cog_slash(name='userinfo', description="get user info", options=[create_option(name="name", description="Name", option_type=3, required=True)])
async def _userinfo(self, ctx, name):
await ctx.send(name)
在main.py
from discord_slash import SlashCommand
client = commands.Bot(...)
slash = SlashCommand(client, sync_commands=True)