如何使 bot 运行 成为斜杠命令 discord.py

How to make bot run a slash command discord.py

我正尝试在 repl.it 上使用 selfbot 运行 发送斜杠命令,但它们作为普通消息发送,未被检测为斜杠命令。

我知道 discord selfbots 反对 TOS 但出于测试目的,我将如何制作它以便它们检测为斜杠命令?

代码如下:

import discord
import os
import keep_alive
from discord.ext import commands, tasks

bot = commands.Bot(command_prefix='!', self_bot=True, help_command=None)

@bot.event
async def on_ready():
    print("Bot presence t u r n e d on ( ͡° ͜ʖ ͡°)")
    test.start()

@tasks.loop(seconds=10)
async def test():
    channel = bot.get_channel(xxx)
    await channel.send('/nick test nick')

keep_alive.keep_alive()
bot.run(xxx, bot=False)

谢谢。

Discord 将斜线命令检测为交互而非实际命令。我在网上找到了这段代码,供某人从 2022 年 3 月起在他们的服务器中设置斜杠命令:

@tree.command(guild = discord.Object(id=guild_id), name = 'tester', description='testing') #guild specific slash command
async def slash2(interaction: discord.Interaction):
    await interaction.response.send_message(f"I am working! I was made with Discord.py!", ephemeral = True)
    ## Ephemeral being "true" means it will only display for the user running the command

希望有用。