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

Discord-py移动成员功能故障求助:求示例与解决建议

Hey there! Let's figure out why your discord.py bot's member moving feature isn't working and fix it up. I’ve dealt with similar issues before, so here’s a breakdown of what to check plus working code examples to get you sorted.

First: Double-Check Permissions

This is the most common culprit! Make sure your bot has all the right permissions to move members:

  • Your bot account must have the Move Members permission enabled at the server level
  • The bot also needs the Connect permission in both the source voice channel (where the member is currently) and the target voice channel
  • Important: The bot can’t move members with a higher role hierarchy than itself (like server admins)
Working Example Code

Below are two practical examples depending on how you want to trigger the move:

Command-Based Member Move

This lets users with the right permissions trigger a move via a command:

import discord
from discord.ext import commands

# Enable required intents - critical for voice state and member data
intents = discord.Intents.default()
intents.members = True
intents.voice_states = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.command(name='move')
@commands.has_permissions(move_members=True)  # Ensure the command user has permission to move members
async def move_member(ctx, member: discord.Member, target_channel: discord.VoiceChannel):
    # Check if the member is actually in a voice channel
    if not member.voice:
        await ctx.send(f"{member.display_name} isn't in any voice channel right now!")
        return
    
    try:
        await member.move_to(target_channel)
        await ctx.send(f"Successfully moved {member.display_name} to {target_channel.name}")
    except discord.Forbidden:
        await ctx.send("I don't have enough permissions to move this member!")
    except discord.HTTPException as e:
        await ctx.send(f"Oops, something went wrong moving the member: {e}")
    except Exception as e:
        await ctx.send(f"Unexpected error: {str(e)}")

bot.run('YOUR_BOT_TOKEN_HERE')

Auto-Move on Voice Join

This example automatically moves members when they join a specific channel:

@bot.event
async def on_voice_state_update(member, before, after):
    # Trigger when a member joins the "Waiting Room" channel
    if after.channel and after.channel.name == "Waiting Room":
        # Find the target channel (replace with your channel name)
        target_channel = discord.utils.get(member.guild.channels, name="General Chat")
        if target_channel:
            try:
                await member.move_to(target_channel)
                print(f"Moved {member.display_name} to General Chat")
            except discord.Forbidden:
                print("Lack permissions to move this member")
            except Exception as e:
                print(f"Failed to move member: {str(e)}")
Troubleshooting Common Errors
  • Forbidden (403): Your bot lacks permissions. Double-check server and channel-level permissions, and ensure the bot's role is higher than the member's role you're trying to move.
  • NotFound (404): Either the target channel doesn't exist, or the member isn't in a voice channel. Verify your channel names/IDs and member status.
  • Intent-related errors: You forgot to enable members or voice_states intents. Head to your Discord Developer Portal > Bot > Privileged Gateway Intents and toggle these on, then make sure they're enabled in your code too.
  • MemberNotFound: The command couldn't parse the member correctly. Use a mention (@Username) or the member's ID when running the command.
  • HTTPException: This usually means a temporary Discord API issue, or the target channel is full (if it has a user limit).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 09:00:36