【问题标题】:Making a Slash Command appear in Discord UI使斜线命令出现在 Discord UI 中
【发布时间】:2022-01-03 18:28:16
【问题描述】:

不和谐,模块discord.ext.commands 允许您创建命令。我尝试创建一个带有前缀="/" 的命令,尽管它不会出现在 discord 的 UI 中。

代码:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="/")

@bot.command(name="kick", description="Kick a user to your wish.")
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
    await member.kick(reason=reason)
    await ctx.send(f"The user @{member} has been kicked. Reason: {reason}.")

bot.run("mytoken")

它不会弹出。

但我想这样做:

【问题讨论】:

    标签: python discord discord.py bots


    【解决方案1】:

    你需要安装discord-py-slash-command,然后把代码导入from discord-py-slash-command import SlashCommands。您可以参考以下代码:

    import discord
    from discord_slash import SlashCommand
    client = discord.Client(intents=discord.Intents.all())
    slash = SlashCommand(client, sync_commands=True) # Declares slash commands through the client.
    
    guild_ids = [1234567890] # Put your server IDs in this array.
    
    @slash.slash(name="ping", guild_ids=guild_ids)
    async def _ping(ctx):
        await ctx.send("Pong!")
    
    client.run("token")
    

    【讨论】:

      猜你喜欢
      • 2023-03-17
      • 2021-05-09
      • 2021-10-06
      • 2022-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-24
      • 2021-12-31
      相关资源
      最近更新 更多