【问题标题】:Making a discord.py bot use external commands让 discord.py 机器人使用外部命令
【发布时间】:2021-03-10 03:03:38
【问题描述】:

我打算制作一个通用机器人,它也可以调用其他机器人。有什么想法吗?

import os
import discord
import time
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()

TOKEN = os.getenv("DISCORD_TOKEN")
bot = commands.Bot(command_prefix = ".")

@bot.event
async def on_ready():
    print(f"{bot.user.name} is ready")

#---------------------------------------#
@bot.command(name = "bot_interact")
async def join(ctx, voice_channel: commands.VoiceChannelConverter):
    await voice_channel.connect()
    await ctx.send("-play (desired_song)")
    time.sleep(2)
    await ctx.send("-loop")

@bot.command(name = "leave")
async def leave(ctx):
    server = ctx.message.guild.voice_client
    await server.disconnect()
#---------------------------------------#

bot.run(TOKEN)

此外,我把它写得太满了,所以你可以具体看到我想要做什么,这是我的机器人来引起 Groovy 的注意,并告诉 Groovy,我想播放这首歌。请记住,我对 python 比较陌生,我没有使用太多。提前谢谢

【问题讨论】:

  • 大多数机器人不允许与其他机器人交互,我认为这是不可能的,尤其是在 Groovy 中。

标签: python discord.py


【解决方案1】:

机器人几乎总是被设计为忽略任何其他机器人的消息。没有这个,机器人可能会进入无限循环。

Groovy 做同样的事情;它将忽略机器人发送的所有其他消息。

【讨论】:

    猜你喜欢
    • 2020-07-09
    • 2021-01-01
    • 2021-10-06
    • 2022-01-10
    • 2020-10-26
    • 1970-01-01
    • 2021-08-10
    • 2020-12-12
    • 2023-01-13
    相关资源
    最近更新 更多