MKE0108 commited on
Commit
5d5b368
·
1 Parent(s): 1d9bb10
Files changed (1) hide show
  1. bot_main.py +18 -10
bot_main.py CHANGED
@@ -42,9 +42,10 @@ async def info(ctx):
42
  embed.add_field(name="ID", value=bot.user.id, inline=True)
43
  embed.add_field(name="伺服器數量", value=len(bot.guilds), inline=True)
44
  await ctx.send(embed=embed)
45
-
46
  import random
47
- def get_pick_embed(player):
 
48
  if(len(player) > 5):
49
  # 紅色顯示
50
  return discord.Embed(title="抽獎結果", color=0xff0000, description="人數超過5人")
@@ -64,17 +65,19 @@ def get_pick_embed(player):
64
  @app_commands.describe(channel_name="語音頻道名稱",other_user="其他玩家名稱")
65
  async def pick(ctx, channel_name:str="",other_user:str=""):
66
  #尋找最接近的語音頻道
67
- voice_channel_list = ctx.guild.voice_channels
68
- text_to_match = channel_name
69
- closest_match = difflib.get_close_matches(text_to_match, voice_channel_list, n=1)
70
  closest_match = closest_match[0] if closest_match else None
71
- channel_name = closest_match
72
-
73
  # 搜尋指定名稱的語音頻道
74
- voice_channel = discord.utils.get(ctx.guild.voice_channels, name=channel_name)
75
  try:
 
 
 
76
  members = voice_channel.members
77
- member_names = [member.name for member in members]
 
78
  except:
79
  member_names = []
80
  if(other_user != ""):
@@ -83,6 +86,11 @@ async def pick(ctx, channel_name:str="",other_user:str=""):
83
  await ctx.send("沒東東")
84
  return
85
  embed = get_pick_embed(member_names)
86
- await ctx.send(embed=embed)
 
 
 
 
 
87
 
88
  bot.run(os.getenv('BOT_TOKENS'))
 
42
  embed.add_field(name="ID", value=bot.user.id, inline=True)
43
  embed.add_field(name="伺服器數量", value=len(bot.guilds), inline=True)
44
  await ctx.send(embed=embed)
45
+ import copy
46
  import random
47
+ def get_pick_embed(player_source):
48
+ player=player_source.copy()
49
  if(len(player) > 5):
50
  # 紅色顯示
51
  return discord.Embed(title="抽獎結果", color=0xff0000, description="人數超過5人")
 
65
  @app_commands.describe(channel_name="語音頻道名稱",other_user="其他玩家名稱")
66
  async def pick(ctx, channel_name:str="",other_user:str=""):
67
  #尋找最接近的語音頻道
68
+ voice_channel_list = [item.name.upper() for item in ctx.guild.voice_channels]
69
+ text_to_match = channel_name.upper()
70
+ closest_match = difflib.get_close_matches(text_to_match, voice_channel_list, n=1, cutoff=0.2)
71
  closest_match = closest_match[0] if closest_match else None
72
+
 
73
  # 搜尋指定名稱的語音頻道
 
74
  try:
75
+ idx=voice_channel_list.index(closest_match)
76
+ channel_name=ctx.guild.voice_channels[idx].name
77
+ voice_channel = discord.utils.get(ctx.guild.voice_channels, name=channel_name)
78
  members = voice_channel.members
79
+ print(members)
80
+ member_names = [member.global_name if member.nick==None else member.nick for member in members]
81
  except:
82
  member_names = []
83
  if(other_user != ""):
 
86
  await ctx.send("沒東東")
87
  return
88
  embed = get_pick_embed(member_names)
89
+ tmp=channel_name if channel_name!="" else '沒有指定'
90
+ remessage = f"### 🎙️ {tmp}"
91
+ tmp=" ".join(member_names)
92
+ remessage += f" 👥 {tmp}"
93
+ await ctx.send(remessage,embed=embed)
94
+
95
 
96
  bot.run(os.getenv('BOT_TOKENS'))