【问题标题】:How do I get input in an option in discordpy?如何在不和谐的选项中获得输入?
【发布时间】:2021-12-26 19:23:33
【问题描述】:

我正在为机器人处理此命令,但我不确定如何在选项后获取文本,例如: /userinfo name: Hatsune Miku 最后打印出hatsune miku。

【问题讨论】:

    标签: python discord slash


    【解决方案1】:

    如果您使用的是不和谐互动,您可以这样做:

    在齿轮中

    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)
    

    【讨论】:

    • 我不使用 cogs,但其他人在 Discord 中帮助我解决了这个问题,尽管感谢您的回答。真的很感激。
    猜你喜欢
    • 2021-03-04
    • 2021-02-26
    • 2022-10-23
    • 1970-01-01
    • 2020-11-21
    • 2022-11-21
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多