【问题标题】:python - Is there a way to make a discord bot listen to another discord bot?python - 有没有办法让不和谐的机器人听另一个不和谐的机器人?
【发布时间】:2023-04-04 08:19:02
【问题描述】:

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

bot1.py

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

bot2.py

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

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

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

【问题讨论】:

  • 解释您的用户案例以及如何使用它以及为什么。
  • 我认为这会很有趣吗?我猜只是供我使用。

标签: python discord discord.py


【解决方案1】:

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

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")

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

【讨论】:

  • 显然成功了!请注意,从第 3 行开始,两个文件都需要缩进,bot2.py 的最后一行需要为 await channel.send("$loop1")
猜你喜欢
  • 1970-01-01
  • 2021-06-30
  • 2021-10-30
  • 2021-05-27
  • 2021-07-15
  • 2021-11-18
  • 2018-03-20
  • 2019-04-13
  • 2022-10-24
相关资源
最近更新 更多