async def set_user(self, ctx, role: discord.Role): """Userが入ってきた時に付与する役職を指定 引数にUserに付与する役職を指定する。Userが入ってきたらその役職を付与 role: 名前・ID・メンション 別名: su """ if not self.member_not_is_bot.get(str(ctx.guild.id)): self.member_not_is_bot[str(ctx.guild.id)] = {} self.member_not_is_bot[str(ctx.guild.id)]['member_role_id'] = str( role.id) date.save(self.member_not_is_bot, 'member_not_is_bot')
async def set_bumper(self, ctx, role: discord.Role): """ 引数に指定した役職に通知が飛ぶように設定するコマンドだよ! role: 名前・ID・メンション 別名: sbp """ guild_id = str(ctx.guild.id) if not self.bump_time.get(guild_id): self.bump_time[guild_id] = {} self.bump_time[guild_id]['bump_role'] = str(role.id) date.save(self.bump_time, 'bump_time') await ctx.send(f'**{role.name}**に通知が行くように設定したよ!')
async def reset_role(self, ctx): """指定された役職を持つ人数を表示するVCを作成 引数には複数の役職を指定可能 roles: 名前・ID・メンション 別名: svm """ guild_id = str(ctx.guild.id) if not self.role_counter.get(guild_id): self.role_counter[guild_id] = {} return self.role_counter.pop(guild_id) date.save(self.role_counter, 'role_counter') await ctx.send(f'{ctx.guild.name}: roleVCの設定を削除しました')
async def set_vc_bot(self, ctx, role: discord.Role): """チャンネルを管理するBOTの役職を設定 BOTに統一して付いてる役職を設定して下さい。 別名: svm """ guild_id = str(ctx.guild.id) if not self.counter.get(guild_id): self.counter[guild_id] = {} self.counter[guild_id]['bot_role_id'] = str(role.id) date.save(self.counter, 'member_counter') await ctx.send(f'BOTの役職を{role.name}に設定しました')
async def set_create_text(self, ctx, text: str = 'チャンネルの名前を変更してね'): """特定のカテゴリー内に固定するテキストチャンネルを作成 引数にボイスチャンネルの名前を指定することにより、固定のテキストチャンネルを作成 text: 文字列 別名: st """ new_text = await ctx.channel.category.create_text_channel(name=text) if not self.create_text.get(str(ctx.guild.id)): self.create_text[str(ctx.guild.id)] = {} self.create_text[str(ctx.guild.id)]['サーバー名'] = ctx.guild.name self.create_text[str(ctx.guild.id)]['テキストチャンネルID'] = [] self.create_text[str(ctx.guild.id)]['テキストチャンネルID'].append( str(new_text.id)) date.save(self.create_text, 'text') await ctx.send(f'自動作成チャンネル{new_text.mention}を作成しました')
async def poll_channel(self, ctx, channel: discord.TextChannel, opt=None): if opt is None: opt = "global" if opt not in ["global", "yn", "custom"]: return if self.load.get(str(ctx.guild.id)) is None: self.load[str(ctx.guild.id)] = {} if self.load[str(ctx.guild.id)].get(opt) is None: self.load[str(ctx.guild.id)][opt] = None self.load[str(ctx.guild.id)][opt] = str(channel.id) date.save(self.load, "poll_channel") await ctx.send(f"{channel.mention}をアンケートチャンネルに設定しました")
async def set_vc_role(self, ctx, roles: commands.Greedy[discord.Role]): """指定された役職を持つ人数を表示するVCを作成 引数には複数の役職を指定可能 roles: 名前・ID・メンション 別名: svm """ guild_id = str(ctx.guild.id) if not self.role_counter.get(guild_id): self.role_counter[guild_id] = {} for role in roles: new_voice = await ctx.guild.create_voice_channel( name=f"{role.name}人数: {len(role.members)}") for member in ctx.guild.members: try: if member.id == 693839038200938547: bot_role = ctx.guild.get_role( int(self.counter[guild_id]['bot_role_id'])) await new_voice.set_permissions(bot_role, manage_channels=True) else: await new_voice.set_permissions(member, connect=False) except discord.errors.Forbidden: pass await ctx.send(f'{role.name}人数: {len(role.members)}を作成しました') counter = 0 while True: if self.role_counter[guild_id].get(str(counter)): counter = counter + 1 continue elif not self.role_counter[guild_id].get(str(counter)): self.role_counter[guild_id][str(counter)] = {} self.role_counter[guild_id][str(counter)]['voice_channel'] = str( new_voice.id) self.role_counter[guild_id][str(counter)]['role_id'] = str(role.id) date.save(self.role_counter, 'role_counter') break
async def remove_voice(self, ctx, voice: VoiceChannel = None): """指定されたボイスチャンネルを固定ボイスチャンネルから除外 voice: 名前・ID 別名: rv """ if voice is None: return await ctx.send('voiceが指定されていません') if not self.create_voice.get(str(ctx.guild.id)): self.create_voice[str(ctx.guild.id)] = {} return for k in self.create_voice[str(ctx.guild.id)].keys(): if k == str(voice.id): self.create_voice[str(ctx.guild.id)].pop(str(voice.id)) date.save(self.create_voice, 'voice') await ctx.send(f'ボイスチャンネル一覧から{voice.name}を除外したよ!')
async def set_create_voice(self, ctx, voice: str, user_limit: int = 99): """特定のカテゴリー内に固定するボイスチャンネルを作成 引数にボイスチャンネルの名前を指定することにより、固定のボイスチャンネルを作成\n ユーザーリミットを指定することにより、そのボイスチャンネルに入れる人数を制限する voice: 文字列 user_limit: int (デフォルト値: 99) 別名: sv """ if not self.create_voice.get(str(ctx.guild.id)): self.create_voice[str(ctx.guild.id)] = {} self.create_voice[str(ctx.guild.id)]['ボイスチャンネルカウント'] = str(1) date.save(self.create_voice, 'voice') new_voice = await ctx.channel.category.create_voice_channel( name=f"{voice}", user_limit=user_limit) self.create_voice[str(ctx.guild.id)][str(new_voice.id)] = {} date.save(self.create_voice, 'voice') await ctx.send(f'{user_limit}人制限で{new_voice.name}を作成しました')
async def set_enable(self, ctx, enable: str = 'on'): """ 引数にon(有効)/off(無効)を渡すことにより、bumpの通知時にメンションのオン・オフを切り替えます。 enable: on/off 別名: sen """ guild_id = str(ctx.guild.id) if not self.bump_time.get(guild_id): self.bump_time[guild_id] = {} if enable == 'on': self.bump_time[guild_id]['enable_mention'] = 'on' elif enable == 'off': self.bump_time[guild_id]['enable_mention'] = 'off' date.save(self.bump_time, 'bump_time') mention_enable = '有効化' if enable == 'on' else '無効化' await ctx.send(f'メンションを{mention_enable}したよ!')
async def on_message(self, mes): admin = self.bot.get_channel(696591762042650644) guild_id = str(mes.guild.id) if mes.author.id == 693839038200938547: return if mes.mention_everyone: channel = self.bot.get_channel(696409125403230238) if not self.spamer.get(str(mes.guild.id)): self.spamer[str(mes.guild.id)] = {} if not self.spamer[str(mes.guild.id)].get(str(mes.author.id)): self.spamer[str(mes.guild.id)][str(mes.author.id)] = {} if not self.spamer[str(mes.guild.id)][str( mes.author.id)].get('開始時刻'): self.spamer[str(mes.guild.id)][str( mes.author.id)]['開始時刻'] = str(datetime.now().second) self.spamer[str(mes.guild.id)][str(mes.author.id)]['終了時刻'] = str( datetime.now().second) if self.spamer[str(mes.guild.id)][str(mes.author.id)].get('回数'): self.spamer[str(mes.guild.id)][str(mes.author.id)]['回数'] = str( int(self.spamer[str(mes.guild.id)][str(mes.author.id)] ['回数']) + 1) elif not self.spamer[str(mes.guild.id)][str( mes.author.id)].get('回数'): self.spamer[str(mes.guild.id)][str( mes.author.id)]['回数'] = str(1) date.save(self.spamer, 'spamer') e = discord.Embed(title='メンションスパム') e.add_field(name='名前', value=str(mes.author), inline=False) e.add_field(name='ID', value=mes.author.id, inline=False) if int(self.spamer[str(mes.guild.id)][str( mes.author.id)]['回数']) >= 5: if int(self.spamer[str(mes.guild.id)][str( mes.author.id)]['終了時刻']) - int(self.spamer[str( mes.guild.id)][str(mes.author.id)]['開始時刻']) < -10: await mes.author.ban(delete_message_days=7, reason='メンションスパム') if mes.guild.id == 695801973127118899: await channel.send(embed=e) elif (self.spamer[str(mes.guild.id)][str( mes.author.id)]['開始時刻'] == 59) and (self.spamer[str( mes.guild.id)][str(mes.author.id)]['終了時刻'] == 4): await mes.author.ban(delete_message_days=7, reason='メンションスパム') if mes.guild.id == 695801973127118899: await channel.send(embed=e) elif (self.spamer[str(mes.guild.id)][str( mes.author.id)]['開始時刻'] == 58) and (self.spamer[str( mes.guild.id)][str(mes.author.id)]['終了時刻'] == 3): await mes.author.ban(delete_message_days=7, reason='メンションスパム') if mes.guild.id == 695801973127118899: await channel.send(embed=e) elif (self.spamer[str(mes.guild.id)][str( mes.author.id)]['開始時刻'] == 57) and (self.spamer[str( mes.guild.id)][str(mes.author.id)]['終了時刻'] == 2): await mes.author.ban(delete_message_days=7, reason='メンションスパム') if mes.guild.id == 695801973127118899: await channel.send(embed=e) elif (self.spamer[str(mes.guild.id)][str( mes.author.id)]['開始時刻'] == 56) and (self.spamer[str( mes.guild.id)][str(mes.author.id)]['終了時刻'] == 2): await mes.author.ban(delete_message_days=7, reason='メンションスパム') if mes.guild.id == 695801973127118899: await channel.send(embed=e) elif (self.spamer[str(mes.guild.id)][str( mes.author.id)]['開始時刻'] == 55) and (self.spamer[str( mes.guild.id)][str(mes.author.id)]['終了時刻'] == 00): await mes.author.ban(delete_message_days=7, reason='メンションスパム') if mes.guild.id == 695801973127118899: await channel.send(embed=e) elif mes.mentions: if str(mes.channel.id) in self.not_mention[guild_id]['channel_id']: if not self.not_mention[guild_id].get('custom_message'): await admin.send( f'{mes.author.mention}さん此処のチャンネルではメンション禁止だよ。') elif self.not_mention[guild_id].get('custom_message'): await mes.channel.send( self.not_mention[guild_id]['custom_message'])
async def on_message(self, mes): if mes.author.bot: return if mes.content.startswith('e!'): return if mes.embeds: return if not self.create_text.get(str(mes.guild.id)): return if not self.create_text[str(mes.guild.id)].get('テキストチャンネルID'): return test_channel = self.bot.get_channel(699274063142715484) if str(mes.channel.id) in self.create_text[str( mes.guild.id)]['テキストチャンネルID']: if len(mes.content) >= 30: return await mes.channel.send( 'メッセージが30文字を超えてるため、エラーが発生しました。30文字以内に抑えて新規作成してください。') await mes.delete() overwrites = { mes.author: PermissionOverwrite(manage_channels=True) } new_channel = await mes.channel.category.create_text_channel( name=mes.content, overwrites=overwrites) get_new_channel = utils.get(mes.channel.category.text_channels, name=mes.content) e = Embed(description=f'新規チャンネル{get_new_channel.mention}を作成しました') e.add_field(name='対象ユーザー', value=mes.author.mention) await mes.channel.send(embed=e) if not self.new_text.get(str(mes.guild.id)): self.new_text[str(mes.guild.id)] = {} if not self.new_text[str(mes.guild.id)].get(str(mes.author.id)): self.new_text[str(mes.guild.id)][str(mes.author.id)] = {} if not self.new_text[str(mes.guild.id)][str( mes.author.id)].get('new_channel'): self.new_text[str(mes.guild.id)][str( mes.author.id)]['new_channel'] = [] if str(new_channel.id) not in self.new_text[str(mes.guild.id)][str( mes.author.id)]['new_channel']: self.new_text[str(mes.guild.id)][str( mes.author.id)]['new_channel'].append(str(new_channel.id)) date.save(self.new_text, 'new_channel') e = Embed(description=f'{mes.author.mention}\n{mes.content}') await new_channel.send(embed=e) if str(mes.channel.id) in self.new_text[str(mes.guild.id)][str( mes.author.id)]['new_channel']: await mes.add_reaction('\U0001f5d1')
async def on_voice_state_update(self, member, before, after): if before.channel is None: if not self.create_voice.get(str(member.guild.id)): return elif not self.create_voice[str(member.guild.id)].get('bot_role'): return if len(after.channel.members) == 1: if str(after.channel.id) in self.create_voice[str( member.guild.id)].keys(): new_voice = await after.channel.clone() await new_voice.edit( name= f"{after.channel.name}-{self.create_voice[str(member.guild.id)]['ボイスチャンネルカウント']}" ) await member.move_to(new_voice) self.create_voice[str(member.guild.id)][str( new_voice.id)] = {} self.create_voice[str( member.guild.id)]['ボイスチャンネルカウント'] = str( int(self.create_voice[str(member.guild.id)] ['ボイスチャンネルカウント']) + 1) date.save(self.create_voice, 'voice') elif len(after.channel.members) >= 2: if str(after.channel.id) in self.create_voice[str( member.guild.id)].keys(): new_text = self.bot.get_channel( int(self.create_voice[str(member.guild.id)][str( after.channel.id)]['new_channel'])) return await new_text.set_permissions(member, read_messages=True) if (before.channel is not None) and (after.channel is not None): new_text = await after.channel.category.create_text_channel( name=f"{after.channel.name}") for member_ in member.guild.members: try: if member_ == member: await new_text.set_permissions(member, manage_channels=True) continue elif member_.id == 693839038200938547: role = member.guild.get_role( int(self.create_voice[str( member.guild.id)]['bot_role'])) await new_text.set_permissions(role, manage_channels=True) continue await new_text.set_permissions(member_, read_messages=False) except errors.Forbidden: pass e = Embed(title=f'OWNER: {member}') e.add_field(name='チャンネルの管理権限', value='オン') await new_text.send(embed=e) self.create_voice[str(member.guild.id)][str( after.channel.id)]['new_channel'] = str(new_text.id) self.create_voice[str(member.guild.id)][str( before.channel.id)]['creater'] = str(member.id) date.save(self.create_voice, 'voice') if after.channel is None: if self.create_voice[str(member.guild.id)].get( str(before.channel.id)): new_text = self.bot.get_channel( int(self.create_voice[str(member.guild.id)][str( before.channel.id)]['new_channel'])) if str(before.channel.id) not in self.create_voice[str( member.guild.id)].keys(): return elif len(before.channel.members) == 0: await new_text.delete() await before.channel.delete() self.create_voice[str(member.guild.id)].pop( str(before.channel.id)) date.save(self.create_voice, 'voice') else: await new_text.set_permissions(member, read_messages=False) if len(before.channel.category.voice_channels) == 1: self.create_voice[str( member.guild.id)]['ボイスチャンネルカウント'] = str(1) date.save(self.create_voice, 'voice')