首页 > 解决方案 > python - 有没有办法让不和谐的机器人听另一个不和谐的机器人?

问题描述

我试图制作一个程序来创建一个无限循环,例如:

bot1.py

@bot.command()
async def loop1(ctx):
    await ctx.send('$loop2')

bot2.py

@bot.command()
async def loop2(ctx):
    await ctx.send('$loop1')

但主要问题是机器人不会听另一个机器人,所以这行不通......

有没有办法让一个机器人听另一个机器人?提前致谢!:)

标签: pythondiscorddiscord.py

解决方案


async def也许您可以使用on_message事件而不是使用来定义命令。

bot1.py:

@bot.event
async def on_message(message):
 if message.content.startswith('$loop1'):
     channel = message.channel
     await channel.send("$loop2")

bot2.py:

@bot.event
async def on_message(message):
 if message.content.startswith('$loop2'):
     channel = message.channel
     await channel.send("$loop1")

不完全确定这是否可行,但您可以尝试


推荐阅读