繁体   English   中英

Discord.py 反斜杠命令不起作用

[英]Discord.py kick slash command not working

@slash.slash(
    name="kick",
    description="Kick a member",
    guild_ids=[guildids],
    options=[
        create_option(
            name="user",
            description="The user I should kick",
            required=True,
            option_type=6
            ),
        create_option(
            name="reason",
            description="Why should I kick them?",
            required=False,
            option_type=3
            )
        ]
)
@has_permissions(kick_members=True)
async def _kick(ctx:SlashContext, user:str, reason:str="None Given"):
    reason = str(reason)
    usr = "<@"+str(user.id)+">"
    await user.kick(reason)
    await user.send("Kicked from "+ctx.guild.name+" for "+reason)
    embed = discord.Embed(title="Kicked a user", description="Kicked "+usr+" for reason: "+reason)
    await ctx.send(embed=embed)
    print(ctx.author.name+" used: kick")


# ERRORS
@_kick.error
async def kick_error(ctx:SlashContext, error):
    if isinstance(error, MissingPermissions):
        embed = discord.Embed(title="Permission Error")
        embed.add_field(name="Missing:", value="Kick Members")
        await ctx.send(embed=embed)

当我 /kick user reason 什么都没发生时,它只是让交互失败。 它甚至不会踢用户或向他们发送消息说他们在哪里踢。 由于我的经验不足,我不知道发生了什么。

不要使用user:str 它将user转换为字符串,但你不能踢str object。 只需写user而不是user:str

另请注意,最好使用user.mention而不是"<@"+str(user.id)+">"并阅读 python 中的字符串格式

Discord.py 现在已弃用,不能保证它会在 2022 年正常工作。我建议你转移到其他一些 discord 库或转移到 Javascript 因为它支持命令。

Here is the original post of discord.py discontinued: https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM