【发布时间】:2021-06-02 12:21:39
【问题描述】:
我正在尝试在 discord 上创建一个机器人来用语气指示器标记事物(即 /s 用于讽刺)这个项目一开始只是一个库,但后来我意识到我可以让它将语气指示器附加到末尾使用它作为参数来传递消息。但是,我只能让机器人自己发送,这令人失望,因为它打断了对话的流程。我正在使用python编写它。这是我的代码:
import discord
from discord_slash import SlashCommand, SlashContext # Importing the newly installed library.
client = discord.Client(intents=discord.Intents.all())
slash = SlashCommand(client, sync_commands=True) # Declares slash commands through the client.
guild_ids = [guild id] # Put your server ID in this array.
@client.event
async def on_ready():
print("Ready!")
@slash.slash(name="j", description="joking", guild_ids=guild_ids)
async def j(ctx:SlashContext, message:str): # Defines a new "context" (ctx) command called "ping."
await ctx.respond(eat=True)
send_message = await ctx.send(f"{message} /j")
def check(message):
return message.author.id == ctx.author_id
try:
answer = await bot.wait_for('message', check=check, timeout = 60.0)
except asyncio.TimeoutError:
await ctx.send("You took to long to answer...", hidden=True)
else:
# do something with answer (convert to tone indicator)
pass
client.run("bot token")
我知道我实际上不需要任何最后一部分,但有人建议我将其作为一种解决方法,使其成为用户的 ID。它什么也不返回。有谁知道如何让它以输入命令的用户身份发送,或者像这样屏蔽自己?
【问题讨论】:
标签: python discord discord.py bots