Discord.py bot - 如何让机器人复制我的消息

时间:2021-06-05 14:08:19

标签: python discord bots

我正在使用 Python 进行开发。我想让我的机器人复制上一条消息,其中包含一个特殊命令。

例如,我输入命令 say。所以它看起来像这样:

<块引用>

我:说你在做什么?

<块引用>

机器人:你在做什么?

经过一番研究,我尝试了@Seekii 的代码:

@bot.listen() async def on_message(message):
      if message.content.startswith("!say"):
          await message.channel.send(message.content)

但它显示了不应该显示的整个文本(即使使用 !say 命令)。

3 个答案:

答案 0 :(得分:1)

这对我有用:

@bot.command()
async def say(ctx,*,args): 
    await ctx.send(args)

答案 1 :(得分:1)

@bot.listen()
async def on_message(message):
    if message.content.startswith("!say"):
        await message.channel.send(message.content)

答案 2 :(得分:0)

感谢@UziGoozie 评论和@Seekii 代码,解决这个问题的方法是下一个代码:

async def on_message(message):
    echo = message.content.split(" ", 1)[1]
    if message.content.startswith("!say"):
    await message.channel.send(echo)