我需要将机器人连接到特定的语音通道,定义的意思是:没有 ctx.message.author.voice.channel 我需要它在某个时刻自行连接,这是必要的,因为它会定期飞出通道,我需要它坐在他们 24/7 代码:
import os
import keep_alive
from discord import FFmpegPCMAudio
from discord.ext.commands import Bot
from dotenv import load_dotenv
from discord.utils import get
import discord
import requests
from bs4 import BeautifulSoup as BS
load_dotenv()
TOKEN = ('')
client = Bot(command_prefix="8")
@client.event
async def on_ready():
print('Music Bot Ready')
await client.change_presence(status = discord.Status.online, activity = discord.Game("Создатель: Cameta#4644"))
@client.command(pass_context=True)
async def play(ctx):
global voice
channel = ctx.message.author.voice.channel
voice = get(client.voice_clients, guild = ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
voice.play(FFmpegPCMAudio('http://ep128.hostingradio.ru:8030/ep128'))
@client.command(pass_context=True)
async def stop(ctx):
voice.stop()
@client.command(pass_context=True)
async def info(ctx):
await ctx.send('8play - включить бота, 8stop - выключить бота')
keep_alive.keep_alive()
client.run(TOKEN)
只是
await channel.connect()写而不是await channel.connect(reconnect=True, timeout=None)机器人不应该倒。