我使用voice = await message.author.voice.channel.connect()将我的机器人连接到语音通道,我想让机器人自己连接并使其耳聋
我的所有代码:
client = discord.Client()
@client.event
async def on_ready():
print("Bot is ready!")
@client.event
async def on_message(message):
arg = message.content.split(' ')
if message.content.startswith('>play'):
voice = await message.author.voice.channel.connect()
voice.play(discord.FFmpegPCMAudio(YouTube(arg[1]).streams.first().download()))
await message.guild.change_voice_state(channel=voice, self_mute=True, self_deaf=False)
client.run('my token')发布于 2021-03-19 08:16:03
使用await message.guild.change_voice_state(channel=voice, self_mute=False, self_deaf=True)
复制-粘贴我在查看您的评论后编写的代码:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='>')
@bot.event
async def on_ready():
print("Bot is ready!")
@bot.event
async def on_message(message):
if message.author == bot.user:
return
await bot.process_commands(message)
@bot.command()
async def join(ctx):
if ctx.author.voice is None or ctx.author.voice.channel is None:
return await ctx.send('You need to be in a voice channel to use this command!')
voice_channel = ctx.author.voice.channel
if ctx.voice_client is None:
vc = await voice_channel.connect()
else:
await ctx.voice_client.move_to(voice_channel)
vc = ctx.voice_client
vc.play(discord.FFmpegPCMAudio(YouTube(arg[1]).streams.first().download()))
await ctx.guild.change_voice_state(channel=vc, self_mute=False, self_deaf=True)
bot.run('my token')https://stackoverflow.com/questions/66700629
复制相似问题