0
@bot.command()
async def move(ctx, channel : discord.VoiceChannel):
    for members in ctx.author.voice_channel:
        await members.move_to(channel)

I want the command to be used where the executor can go into a channel and use '.move (name of channel) and then it will move all the members in that channel to the (name of channel). One of the errors I'm getting is that it's ignoring spaces, so if there's a space in the name of the voice channel, it will only include the word before the space. And also I get this: Command raised an exception: AttributeError: 'Member' object has no attribute 'voice_channel'. Can somebody help me?

4

2 回答 2

0

You can use keyword only arguments to process the rest of the message as a single argument. You also need to access the callers voice channel through ctx.author.voice.channel

from discord.ext.commands import check

def in_voice_channel():  # check to make sure ctx.author.voice.channel exists
    def predicate(ctx):
        return ctx.author.voice and ctx.author.voice.channel
    return check(predicate)

@in_voice_channel()
@bot.command()
async def move(ctx, *, channel : discord.VoiceChannel):
    for members in ctx.author.voice.channel.members:
        await members.move_to(channel)
于 2020-01-22T23:47:59.890 回答
0

You need to quote arguments with spaces in them for positional parameters for commands.
Alternatively, you can use a keyword-only argument for the command to consume the rest of the input.

As the exception message is telling you, Member objects do not have a voice_channel attribute.
You'll want to use the Member.voice attribute instead, to get the VoiceState object for that user/member. Then, you can use VoiceState.channel for the VoiceChannel that the user/member is connected to.

Also, note that you can't iterate VoiceChannel itself for the members connected to that voice channel. You'll want to use the VoiceChannel.members attribute instead.

于 2020-01-23T00:06:06.720 回答