python - 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')
但主要问题是机器人不会听另一个机器人,所以这行不通......
有没有办法让一个机器人听另一个机器人?提前致谢!:)
解决方案
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")
不完全确定这是否可行,但您可以尝试
推荐阅读
- javascript - 如何从日期数组中获取最新日期?- Javascript/打字稿
- node.js - npm install 给出 ENOENT 错误
- java - cassandra 插入和更新
- intellij-idea - 尽管设置了 GRADLE_HOME 变量,IntelliJ 仍不断询问 Gradle Location
- nested - Rust 中的嵌套常量
- ruby-on-rails - 如何查看模型是否存在,如果不使用单个表单则创建?
- c# - 控制器服务依赖注入问题 - Asp.net 框架
- c# - 带有 JObject 元素的 C# JsonResult 返回空数组
- angular - CMD 中的 NPM 安装问题
- javascript - 更新 Firebase 实时数据库中的现有值