【发布时间】:2021-12-26 19:23:33
【问题描述】:
我正在为机器人处理此命令,但我不确定如何在选项后获取文本,例如:
/userinfo name: Hatsune Miku
最后打印出hatsune miku。
【问题讨论】:
我正在为机器人处理此命令,但我不确定如何在选项后获取文本,例如:
/userinfo name: Hatsune Miku
最后打印出hatsune miku。
【问题讨论】:
如果您使用的是不和谐互动,您可以这样做:
在齿轮中
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)
【讨论】: