python - 我想将歌曲的名称作为参数传递
问题描述
在消息中输入歌曲标题后,我想使用参数播放歌曲标题文件。
例如,如果您在消息中键入 [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")
解决方案
推荐阅读
- java - 如何解决此存储库错误?似乎没有任何效果
- laravel - htaccess 帮助:将域重定向到公用文件夹,但在 URL 中仍显示没有公用文件夹的主域
- reactjs - 使用过滤器函数数组的反应表过滤器表
- java - log4j & Apache Kafka - 禁用特定的日志输出
- android - 如何在 do while 循环中连续显示 AlertDialog 直到满足某个条件?
- reactjs - 无法启动 React 项目
- java - WebSocket 如何(以什么顺序)处理请求?
- reactjs - 函数名 {function()} 和组件名的区别
在反应渲染功能中? - .htaccess - 在 htaccess 文件中使用 modrewrite 进行 URL 转发
- symfony5 - Symfony 5:验证多个警卫和不同的提供者