首页 > 解决方案 > 我想将歌曲的名称作为参数传递

问题描述

在消息中输入歌曲标题后,我想使用参数播放歌曲标题文件。

例如,如果您在消息中键入 [test],则会播放文件 test。我想声明一个函数来简化它。

import discord
import subprocess
import asyncio
from discord import FFmpegPCMAudio, PCMVolumeTransformer, AudioSource
from discord.ext import commands

bot = commands.Bot(command_prefix='.')


@bot.command()
async def join(ctx):
    connected = ctx.author.voice
    if connected:
        await connected.channel.connect()

@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()

@bot.command()
async def play(self,musicname):
    await message.add_reaction("✅")
    if voice.is_connected():
        source = discord.FFmpegPCMAudio(musicname+".mp3")
        voice_client.play(source)


bot.run("my_token")

标签: pythondiscorddiscord.py

解决方案


推荐阅读