python - Move all members to channel command using a foor loop discord.py
问题描述
@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?
解决方案
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)
推荐阅读
- xaml - 图像未显示在 MVVM XAML Xamarin 表单上
- python - 通过python加载xgen预览
- python - Plotly Scatter3d:如何强制 3D 轴具有相同的比例/纵横比?
- facebook - 使用 v3.1 Graph API Explorer 访问 facebook 信息
- javascript - 基于父属性值的jQuery悬停效果
- php - 如何在没有http的情况下找到所有带有可能连字符的jpg?
- r - 需要帮助在 R 中编写答案
- javascript - 会话和刷新
- r - R在超链接中添加变量
- windows - mkdir 返回命令的语法在 windows 上不正确