简体   繁体   English

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

[英]Discord.py bot - how to make bot copy my message

I'm developing in Python.我正在开发 Python。 I'd like to make my bot copying the previous message, which contains a special command for this.我想让我的机器人复制上一条消息,其中包含一个特殊的命令。

For example, I type the command say .例如,我输入命令say So it would look like this:所以它看起来像这样:

Me: say What are you doing?我:说你在做什么?

Bot: What are you doing?博特:你在做什么?

After some research I tried @Seekii's code:经过一番研究,我尝试了@Seekii 的代码:

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

But it shows the entire text (even with !say command) which shouldn't be.但它显示了不应该显示的整个文本(即使使用!say命令)。

This work for me:这对我有用:

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

Thanks to @UziGoozie comment and @Seekii code, the solution to this problem is the next code:感谢@UziGoozie 评论和@Seekii 代码,这个问题的解决方案是下一个代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM