Skip to content

Commit

Permalink
返信的要素をもつsendをreplyに変更(discord.py:1.6.0から使用できる機能)
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuya-ki committed Feb 11, 2021
1 parent 446c7d5 commit ec1f585
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions cogs/admincog.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async def make(self, ctx, channelName=None):
# 念の為、確認する
confirm_text = f'{category_text}パブリックなチャンネル **{channelName}** を作成してよろしいですか? 問題ない場合、30秒以内に👌(ok_hand)のリアクションをつけてください。\nあなたのコマンド:`{ctx.message.clean_content}`'
await ctx.message.delete()
await ctx.channel.send(confirm_text)
confirm_msg = await ctx.channel.send(confirm_text)

def check(reaction, user):
return user == self.command_author and str(reaction.emoji) == '👌'
Expand All @@ -203,7 +203,7 @@ def check(reaction, user):
try:
reaction, user = await self.bot.wait_for('reaction_add', timeout=self.TIMEOUT_TIME, check=check)
except asyncio.TimeoutError:
await ctx.channel.send('→リアクションがなかったのでチャンネル作成をキャンセルしました!')
await confirm_msg.reply('→リアクションがなかったのでチャンネル作成をキャンセルしました!')
else:
try:
# カテゴリが存在しない場合と存在する場合で処理を分ける
Expand All @@ -213,9 +213,9 @@ def check(reaction, user):
# メッセージの所属するカテゴリにテキストチャンネルを作成する
new_channel = await category.create_text_channel(name=channelName)
except discord.errors.Forbidden:
await ctx.channel.send('→権限がないため、チャンネル作成できませんでした!')
await confirm_msg.reply('→権限がないため、チャンネル作成できませんでした!')
else:
await ctx.channel.send(f'<#{new_channel.id}>を作成しました!')
await confirm_msg.reply(f'<#{new_channel.id}>を作成しました!')

# channelコマンドのサブコマンドprivateMake
# チャンネルを作成する
Expand Down Expand Up @@ -318,7 +318,7 @@ async def topic(self, ctx, *, topicWord=None):
original_topic = f'このチャンネルには、トピックとして既に**「{ctx.channel.topic}」**が設定されています。\nそれでも、'
confirm_text = f'{original_topic}このチャンネルのトピックに**「{topicWord}」** を設定しますか? 問題ない場合、30秒以内に👌(ok_hand)のリアクションをつけてください。\nあなたのコマンド:`{ctx.message.clean_content}`'
await ctx.message.delete()
await ctx.channel.send(confirm_text)
confirm_msg = await ctx.channel.send(confirm_text)

def check(reaction, user):
return user == self.command_author and str(reaction.emoji) == '👌'
Expand All @@ -327,15 +327,15 @@ def check(reaction, user):
try:
reaction, user = await self.bot.wait_for('reaction_add', timeout=self.TIMEOUT_TIME, check=check)
except asyncio.TimeoutError:
await ctx.channel.send('→リアクションがなかったので、トピックの設定をキャンセルしました!')
await confirm_msg.reply('→リアクションがなかったので、トピックの設定をキャンセルしました!')
else:
# チャンネルにトピックを設定する
try:
await ctx.channel.edit(topic=topicWord)
except discord.errors.Forbidden:
await ctx.channel.send('→権限がないため、トピックを設定できませんでした!')
await confirm_msg.reply('→権限がないため、トピックを設定できませんでした!')
else:
await ctx.channel.send(f'チャンネル「{ctx.channel.name}」のトピックに**「{topicWord}」**を設定しました!')
await confirm_msg.reply(f'チャンネル「{ctx.channel.name}」のトピックに**「{topicWord}」**を設定しました!')

# channelコマンドのサブコマンドroleDel
# チャンネルのロールを削除する(テキストチャンネルが見えないようにする)
Expand Down Expand Up @@ -402,7 +402,7 @@ async def roleDelete(self, ctx, targetRole=None):
# 念の為、確認する
confirm_text = f'{attention_text}このチャンネルから、ロール**「{targetRole}」** を削除しますか?\n{targetRole}はチャンネルを見ることができなくなります。)\n 問題ない場合、30秒以内に👌(ok_hand)のリアクションをつけてください。\nあなたのコマンド:`{ctx.message.clean_content}`'
await ctx.message.delete()
await ctx.channel.send(confirm_text)
confirm_msg = await ctx.channel.send(confirm_text)

def check(reaction, user):
return user == self.command_author and str(reaction.emoji) == '👌'
Expand All @@ -411,17 +411,17 @@ def check(reaction, user):
try:
reaction, user = await self.bot.wait_for('reaction_add', timeout=self.TIMEOUT_TIME, check=check)
except asyncio.TimeoutError:
await ctx.channel.send('→リアクションがなかったのでチャンネルのロール削除をキャンセルしました!')
await confirm_msg.reply('→リアクションがなかったのでチャンネルのロール削除をキャンセルしました!')
else:
# チャンネルに権限を上書きする
try:
if botRoleUpdateFlag:
await ctx.channel.set_permissions(bot_role, overwrite=bot_overwrite)
await ctx.channel.set_permissions(role, overwrite=overwrite)
except discord.errors.Forbidden:
await ctx.channel.send('→権限がないため、チャンネルのロールを削除できませんでした!')
await confirm_msg.reply('→権限がないため、チャンネルのロールを削除できませんでした!')
else:
await ctx.channel.send(f'チャンネル「{ctx.channel.name}」からロール**「{targetRole}」**の閲覧権限を削除しました!')
await confirm_msg.reply(f'チャンネル「{ctx.channel.name}」からロール**「{targetRole}」**の閲覧権限を削除しました!')

# チャンネル作成時に実行されるイベントハンドラを定義
@commands.Cog.listener()
Expand Down
6 changes: 3 additions & 3 deletions cogs/onmessagecog.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ async def save_message_file(self, targetMessage: discord.Message):

# チャンネルにファイルを添付する(複数ある場合、filesで添付)
if (len(files) > 1):
await targetMessage.channel.send('file upload', files=files)
await targetMessage.reply('file upload', files=files)
elif (len(files) == 1):
await targetMessage.channel.send('file upload', file=files.pop())
await targetMessage.reply('file upload', file=files.pop())
else:
return

Expand All @@ -101,7 +101,7 @@ async def scrapbox_url_expand(self, targetMessage: discord.Message):
if (self.scrapboxSidAndPnames.check(targetMessage)):
embed = await self.scrapboxSidAndPnames.expand(targetMessage)
if embed is not None:
await targetMessage.channel.send(embed=embed)
await targetMessage.reply(embed=embed)
else:
return

Expand Down
6 changes: 3 additions & 3 deletions cogs/reactionchannelercog.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def purge(self, ctx):
# 念の為、確認する
confirm_text = f'全てのリアクションチャンネラーを削除しますか?\n 問題ない場合、30秒以内に👌(ok_hand)のリアクションをつけてください。\nあなたのコマンド:`{ctx.message.clean_content}`'
await ctx.message.delete()
await ctx.channel.send(confirm_text)
confirm_msg = await ctx.channel.send(confirm_text)

def check(reaction, user):
return user == command_author and str(reaction.emoji) == '👌'
Expand All @@ -91,10 +91,10 @@ def check(reaction, user):
try:
reaction, user = await self.bot.wait_for('reaction_add', timeout=self.TIMEOUT_TIME, check=check)
except asyncio.TimeoutError:
await ctx.channel.send('→リアクションがなかったので、リアクションチャンネラーの全削除をキャンセルしました!')
await confirm_msg.reply('→リアクションがなかったので、リアクションチャンネラーの全削除をキャンセルしました!')
else:
msg = await self.reaction_channel.purge(ctx)
await ctx.channel.send(msg)
await confirm_msg.reply(msg)

# リアクションチャンネラー削除(1種類)
@reactionChanneler.command(aliases=['d','del','dlt'], description='リアクションチャンネラーを削除するサブコマンド')
Expand Down

0 comments on commit ec1f585

Please sign in to comment.