You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将未连接语音的用户添加至Discord语音频道?

Discord.py 无法移动未连语音的用户到新频道的解决办法

错误代码40032的原因很明确:Discord API不允许强制将未连接任何语音频道的用户移动到语音频道,这是平台的权限/功能限制,不是代码逻辑问题。

要实现你的需求,只能通过引导用户主动加入的方式,同时优化代码避免报错,具体修改如下:

优化后的代码(修改on_submit方法)

async def on_submit(self, interaction: discord.Interaction):
    category_name = "Games"  
    category = discord.utils.get(interaction.guild.categories, name=category_name)
    vc_name = f"{self.game} - {interaction.user.display_name}"
    vc = await category.create_voice_channel(vc_name)
    chicken = discord.Embed(title= f'Description: {self.info}', timestamp= datetime.now(), type='rich', color=discord.Color.random())
    chicken.add_field(name=' <:gg:1116420203308396556> Game',value=f'{self.game}', inline=True)
    chicken.add_field(name=f' <a:PP:1116409338630770769> Game Mode',value=f' {self.type}', inline=True)
    chicken.add_field(name=f' <a:sq:1116423925430222968> Region Type',value=f'{self.region}', inline=True)
    chicken.add_field(name=' <a:ds:1095220553540968578> VC/Lobby Space', value=f'{len(vc.members)}/{vc.user_limit} members in VC right now!')
    chicken.set_footer(text='use /invite to create your own game invite!', icon_url='https://art.pixilart.com/c4ec72c5f32b864.gif')
    invite = await vc.create_invite(max_age=0, max_uses=0, unique=True)
    chicken.add_field(name=f'**{vc.name} | {vc.category}** ', value=f'**[Click here to join]({invite.url})** ', inline=True)
    chicken.set_author(name=f' {interaction.user.display_name} is looking for party members!', icon_url=f'{interaction.user.guild.icon}', url = 'https://discord.com/users/' + str(interaction.user.id))
    chicken.set_thumbnail(url=f'{str(random.choice(listc))}')

    # 新增:检查用户是否在语音频道
    if interaction.user.voice is not None and interaction.user.voice.channel is not None:
        # 用户当前在语音里,执行移动操作
        await interaction.user.edit(voice_channel=vc)
        await vc.set_permissions(interaction.user,manage_members=True,move_members=True,moderate_members=True)
        await interaction.response.send_message(embed=chicken, content="已帮你移动到新创建的语音频道!")
    else:
        # 用户不在语音里,引导点击链接加入
        await interaction.response.send_message(embed=chicken, content="你当前未连接任何语音频道,请点击上方链接加入新创建的语音频道!")

关键修改点

  • 增加interaction.user.voice状态判断,仅当用户当前处于语音频道时才执行移动操作
  • 用户未在语音时,发送引导消息,让用户通过生成的邀请链接主动加入新VC
  • 避免触发API报错,同时保证功能逻辑顺畅

内容的提问来源于stack exchange,提问作者Janicooking

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 14:47:24