【发布时间】:2021-08-08 05:10:33
【问题描述】:
在我的机器人读取音频文件后,我需要它离开频道。我试图在线路中加入“await voice.disconect()”,但在机器人加入频道后断开了它。如何实现这一点以使机器人在播放文件后离开?
#imports
import discord
from discord.ext import commands
from discord import FFmpegPCMAudio
import random
from discord import embeds
from discord import message
from discord import guild
from discord_slash import SlashCommand
#define client & prefix
client = commands.Bot(command_prefix = '!')
#list of audio for random.choice
Audio = ['LIST OF AUDIO FILES']
#join & play file command
@client.command(pass_context=True)
async def yolk(ctx):
if (ctx.author.voice):
channel = ctx.message.author.voice.channel
voice = await channel.connect()
source = FFmpegPCMAudio(random.choice(Audio))
player = voice.play(source)
else:
await ctx.send("User not in a voice channel, unable to connect.")
client.run('BOT TOKEN')
【问题讨论】:
-
您是否尝试过在断开连接前睡觉? (睡在
await asyncio.sleep(secs) -
@12944qwerty 非常感谢!我什至不知道这是一件事!现在,既然我这样做了,实际上可以解决很多其他问题!谢谢兄弟。
标签: python discord discord.py