简体   繁体   English

DISCORD.PY :我想将所有成员移动到特定频道

[英]DISCORD.PY : I want to move all members to a specific channel

@bot.command()
async def movienight(ctx, member: discord.Member, channel: discord.VoiceChannel):
  await member.move_to(channel)

MY SUFFIX FOR COMMANDS IS !tpl我的命令后缀是 !tpl

if i write on discord !tpl movienight "@member" "channelsname" - then this works and move @member1 to the CHANNELS NAME I WROTE如果我在 discord !tpl movienight "@member" "channelsname" 上写 - 那么这将起作用并将 @member1 移动到我写的频道名称

But i want to make the command look like -> !tpl movienight但我想让命令看起来像 -> !tpl movienight

so it will move everyone connected to another channel to the GENERAL without asking for a @member or for a channels name因此,它将把连接到另一个频道的每个人都转移到 GENERAL,而无需询问@member 或频道名称

@bot.command()
async def movienight(ctx, initial_channel_id: int, move_to_channel_id: int):
   # Get the channels
   initial_channel = discord.utils.get(bot.channels, id=initial_channel_id)
   move_to_channel = discord.utils.get(bot.channels, id=initial_channel_id)
   
   # Check if the channel types are valid
   if not isinstance(initial_channel, (discord.VoiceChannel, discord.StageChannel)):
      await ctx.send('Invalid ID for `initial_channel_id`')
      return
   if not isinstance(move_to_channel, (discord.VoiceChannel, discord.StageChannel)):
      await ctx.send('Invalid ID for `move_to_channel_id`')
      return

   # Move all the members:
   for member in initial_channel.members:
      try:
         member.move_to(move_to_channel, reason='Provide your reason here - optional')
      except discord.Forbidden:
         await ctx.send(f'Trying to move {member} failed')
      else:
         await ctx.send(f'Successfully moved {member}')

   await ctx.send(f'Moved all members from {initial_channel.mention} to {move_to_channel.mention}')

The way you have written the code will give you unnecessary warnings and errors.您编写代码的方式会给您带来不必要的警告和错误。 Since you want to move every member from the initial voice channel, providing a member argument is not required.由于您想从初始语音通道中移动每个成员,因此不需要提供member参数。

initial_channel_id stands for the id of the voice/stage channel where the members originally are, and, move_to_channel_id stands for the id of the voice/stage channel you would like to move the members to. initial_channel_id代表成员最初所在的语音/舞台频道的 ID,而move_to_channel_id代表您要将成员移动到的语音/舞台频道的 ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM