With discord.py, how can I make a slash command only visible to me? example:example of limited visibility command

在我的互联网搜索中,我找到的唯一一件事就是如何发出斜杠命令.有人知道怎么做吗?

推荐答案

@bot.tree.command(name="something")
async def something(interaction:discord.Interaction):
    await interaction.response.send_message("NOTHING",ephemeral=True)
    # optional (if you want to edit the response later,delete it, or send a followup)
    await interaction.edit_original_response(content="Something")
    await interaction.followup.send("This is a message too.",ephemeral=True)
    await interaction.delete_original_response()
    # if you have deleted the original response you can't edit it or send a followup after it

这些都是最基本的.如果您不知道如何加载命令:

@bot.event
async def on_ready():
    print("Bot is online!")
    try:
        synced = await bot.tree.sync()
        print(f"Synced {len(synced)} commands.")
    except Exception as e:
        print(e)

都准备好了!祝你在编码方面好运.如果您需要进一步的帮助,我的不一致是@rexy.py

Python相关问答推荐

Python中的函数中是否有充分的理由接受float而不接受int?

Pandas :多索引组

如何根据日期和时间将状态更新为已过期或活动?

如何才能知道Python中2列表中的巧合.顺序很重要,但当1个失败时,其余的不应该失败或是0巧合

如何在具有重复数据的pandas中对groupby进行总和,同时保留其他列

@Property方法上的inspect.getmembers出现意外行为,引发异常

如何避免Chained when/then分配中的Mypy不兼容类型警告?

非常奇怪:tzLocal.get_Localzone()基于python3别名的不同输出?

按列分区,按另一列排序

ODE集成中如何终止solve_ivp的无限运行

从spaCy的句子中提取日期

driver. find_element无法通过class_name找到元素'""

在Python 3中,如何让客户端打开一个套接字到服务器,发送一行JSON编码的数据,读回一行JSON编码的数据,然后继续?

在Python中使用if else或使用regex将二进制数据如111转换为001""

具有相同图例 colored颜色 和标签的堆叠子图

以异步方式填充Pandas 数据帧

Python Mercury离线安装

如何写一个polars birame到DuckDB

用来自另一个数据框的列特定标量划分Polars数据框中的每一列,

有了Gekko,可以创建子模型或将模型合并在一起吗?