Skip to main content

Pycord 的实用插件

项目描述

标识

实用程序

Pycord的实用插件

特征:

  • 高级音频插件
  • 自定义 Cog 更易于机器人使用
  • 专门用于 Pycord

安装:

稳定的:

pip install --upgrade pycord-utils

发展:

pip install -U git+https://github.com/pycord/utilitys.git

额外选项

使用我们的自定义 Cog

首先安装额外版本的 Pycord Utility

pip install -U pycord-utils[extra]

然后将此添加到您的主机器人文件

bot.load_extension('pycord')

你完成了!

嗓音

使用我们的语音选项安装

pip install -U pycord-utils[voice]

例子

插件用例的小例子

音频示例:

import discord
import pycord
from pycord.ext import audio
from discord.ext import commands

bot = commands.Bot(commands_prefix=">")

class Music(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

        if not hasattr(bot, "audio"):
            self.bot.audio = audio.Client(bot=self.bot)

        self.bot.loop.create_task(self.start_nodes())

    async def start_nodes(self):
        await self.bot.wait_until_ready()

        # Initiate our nodes. For this example we will use one server.
        # Region should be a discord.py guild.region e.g sydney or us_central (Though this is not technically required)
        await self.bot.audio.initiate_node(
            host="0.0.0.0",
            port=2333,
            rest_uri="http://0.0.0.0:2333",
            password="youshallnotpass",
            identifier="TEST",
            region="us_central",
        )

    @commands.command(name="connect")
    async def connect_(self, ctx, *, channel: discord.VoiceChannel = None):
        if not channel:
            try:
                channel = ctx.author.voice.channel
            except AttributeError:
                raise discord.DiscordException(
                    "No channel to join. Please either specify a valid channel or join one."
                )

        player = self.bot.audio.get_player(ctx.guild.id)
        await ctx.send(f"Connecting to **`{channel.name}`**")
        await player.connect(channel.id)

    @commands.command()
    async def play(self, ctx, *, query: str):
        tracks = await self.bot.audio.get_tracks(f"ytsearch:{query}")

        if not tracks:
            return await ctx.send("Could not find any songs with that query.")

        player = self.bot.audio.get_player(ctx.guild.id)
        if not player.is_connected:
            await ctx.invoke(self.connect_)

        await ctx.send(f"Added {str(tracks[0])} to the queue.")
        await player.play(tracks[0])

bot.add_cog(Music(bot))

更多示例可以在示例文件夹中找到。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

Pycord-Utils-1.4.0.tar.gz (1.4 MB 查看哈希

已上传 source