首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使discord bot连接到vc并使其耳聋

使discord bot连接到vc并使其耳聋
EN

Stack Overflow用户
提问于 2021-03-19 07:41:38
回答 1查看 327关注 0票数 0

我使用voice = await message.author.voice.channel.connect()将我的机器人连接到语音通道,我想让机器人自己连接并使其耳聋

我的所有代码:

代码语言:javascript
复制
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')
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-19 08:16:03

使用await message.guild.change_voice_state(channel=voice, self_mute=False, self_deaf=True)

复制-粘贴我在查看您的评论后编写的代码:

代码语言:javascript
复制
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')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66700629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档