実現したいこと
---PayPay自動受け取りbotを作りたい
発生している問題・分からないこと
スラッシュコマンドでPayPayにログインできるようにしたい。
該当のソースコード
type
1import re 2import asyncio 3import paypay 4import discord 5from discord import app_commands 6from discord.ui import Modal, text_input 7 8token = "TOKEN" 9 10intents = discord.Intents.default() 11intents.message_content = True 12client = discord.Client(intents=intents) 13tree = app_commands.CommandTree(client) 14 15 16@client.event 17async def on_ready(): 18 print("起動。") 19 await tree.sync() 20 21 22@client.event 23async def on_message(message): 24 # メッセージ送信者がBotだった場合は無視する 25 if message.author.bot: 26 return 27 if re.search(r'https://pay.paypay.ne.jp', message.content): 28 p_link = re.findall(r'https://pay.paypay.ne.jp/+\w+\w', message.content)[0].replace("https://pay.paypay.ne.jp/", "") 29 print(p_link) 30 c_channel = message.channel 31 c_author = message.author 32 def check(m): 33 return m.author == c_author and m.channel == c_channel 34 pcode_umu = paypay.check_link(p_link) 35 if pcode_umu == "SUCCESS": 36 await message.channel.send("使用済リンクです。") 37 return 38 elif pcode_umu == "Cannot find P2P link": 39 await message.channel.send("受け取りリンクが見つかりません。") 40 return 41 elif pcode_umu == "パスワード付き": 42 await message.channel.send( 43 "パスワード付きリンクを検知しました。\n20秒以内に半角で4桁のパスワードを入力してください 例:0417\nこれを拒否する場合は拒否と入力してください。") 44 try: 45 msg = await client.wait_for('message', check=check, timeout=20) 46 if msg.content == "拒否": 47 await message.channel.send("拒否されました。") 48 return 49 50 try: 51 ererer = int(msg.content) 52 except: 53 await message.channel.send("無効なパスワードです。") 54 return 55 56 pcode_data = (msg.content) 57 except asyncio.TimeoutError: 58 await message.channel.send("タイムアウトしました。") 59 return 60 elif pcode_umu == "パスワード無し": 61 pcode_data = "1919" 62 63 jido_kessai = paypay.start(p_link, pcode_data) 64 try: 65 dataaaaaa = jido_kessai[0] 66 if type(jido_kessai) == list: uketori_st = True 67 else: uketori_st = False 68 except: uketori_st = False 69 if uketori_st == True: 70 embed = discord.Embed( 71 title=f"{jido_kessai[0]}さんから受け取り", 72 description=f"金額:{jido_kessai[2]}円", 73 color=0x00ff00 74 ) 75 embed.set_thumbnail(url=jido_kessai[1]) 76 await message.channel.send(embed=embed) 77 78 79class Md(Modal): 80 a = text_input.TextInput(label='PayPay受け取りリンク', placeholder='https://pay.paypay.ne.jp/HAudjw45', max_length=35, required=True) 81 b = text_input.TextInput(label='パスコード', style=discord.TextStyle.short, required=True, max_length=4, placeholder="1234") 82 83 def __init__(self): 84 super().__init__(title='PayPay受け取り') 85 86 async def on_submit(self, interaction: discord.Interaction): 87 paypay_link = self.a.value.replace("https://pay.paypay.ne.jp/", "") 88 paypay_passcode = self.b.value 89 pcode_umu = paypay.check_link(paypay_link) 90 if pcode_umu == "Cannot find P2P link": 91 await interaction.response.send_message("そのPayPayリンクは存在しません。", ephemeral=True) 92 return 93 uketori = paypay.start(paypay_link, paypay_passcode) 94 try: 95 dataaaaaa = uketori[0] 96 if type(uketori) == list: uketori_st = True 97 else: uketori_st = False 98 except: uketori_st = False 99 if uketori_st == True: 100 embed = discord.Embed( 101 title=f"{uketori[0]}さんから受け取り", 102 description=f"金額:{uketori[2]}円", 103 color=0x00ff00 104 ) 105 embed.set_thumbnail(url=uketori[1]) 106 await interaction.response.send_message(embed=embed, ephemeral=True) 107 else: 108 if uketori == "パスコードが違います": 109 await interaction.response.send_message( 110 "失敗しました。パスコードが間違っていました。お金は2日ほどで戻ってくるのでご安心ください。", ephemeral=True) 111 else: 112 print(uketori) 113 await interaction.response.send_message("失敗しました。リンクが不正だったり、システムエラーが起きていたりしている可能性があります。", ephemeral=True) 114 115@tree.command(name="send_paypay", description="PayPayリンクを送って支援できます。") 116async def test(interaction: discord.Interaction): 117 await interaction.response.send_modal(Md()) 118 119client.run(token)
試したこと・調べたこと
上記の詳細・結果
discord内で、実行すると、必ず失敗しました。と出る
補足
特になし

0 コメント