如何在discord.py中以斜杠命令发送消息?

问题描述 投票:0回答:1

我有一个机器人(我们将其命名为

A
)已连接到频道,并且它有一个斜线命令“/greet”,该命令接受
prompt
并对其进行操作。现在我尝试在这里编写一个机器人
B
,例如发送命令
/greet prompt hello!
,这将触发机器人
A
,并且
A
将为提示提供适当的输出。

问题是,当我运行下面的脚本时,它不明白它应该是斜杠命令,并作为原始字符串发送到不和谐。如何解决这个问题?

import discord
from discord.ext import commands 

discord_token = '' 
channel_id = ""
client = commands.Bot(command_prefix="*", intents=discord.Intents.all()) 

@client.event
async def on_ready():
    print("Bot connected")
    await client.get_channel(int(channel_id)).send('/greet prompt hello')


@client.event
async def on_message(message):
    print(message.content)
    print('We are successfully triggering the bot')

if __name__ == "__main__":
    client.run(discord_token)
python python-3.x discord discord.py bots
1个回答
0
投票

根据 Discord 的开发人员文档 机器人无法使用其他机器人的斜线命令,因为它们无法发送 应用程序命令交互,只能接收它们。

如果另一个机器人也使用常规消息前缀或混合命令(如!greet),您可以使其工作。

如果另一端的机器人是由您开发的,您可以对其进行编程以允许来自第一个机器人的消息命令,但请注意,这样做不是最佳实践。要非常小心,不要创建无限循环。

来源回复:https://stackoverflow.com/a/74494667/19676197

© www.soinside.com 2019 - 2024. All rights reserved.