実現したいこと
ランダムで数字を選択し、スプレッドシートからその数字の行を抽出する処理をしています。
コマンドを実行すると、他のボット機能が使用できなくなると思い調べたら、「run_in_executor」というものがあり、試してみましたが、下記のようなエラーが出てしまいます。
自分なりに色々と調べてみましたが、よく分からなかったので質問させていただきます。
発生している問題・エラーメッセージ
<Future pending cb=[_chain_future.<locals>._call_check_cancel() at C:\Users\aaaa\AppData\Local\Programs\Python\Python310\lib\asyncio\futures.py:385]>
該当のソースコード
py
12import discord 3from discord import app_commands 4from discord.ext import commands 5import asyncio 6 7import random 8import gspread 9from oauth2client.service_account import ServiceAccountCredentials 10from gspread_dataframe import set_with_dataframe 11 12def get_sheet(sheet_name):13 SCOPES = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']14 SERVICE_ACCOUNT_FILE = 'infinite-chain-251218-5f4c25cbc2f7.json'15 credentials = ServiceAccountCredentials.from_json_keyfile_name(SERVICE_ACCOUNT_FILE,SCOPES)16 gs = gspread.authorize(credentials)17 SPREADSHEET_KEY = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'18 worksheet = gs.open_by_key(SPREADSHEET_KEY).worksheet(sheet_name)19 return worksheet 20 21 22async def dataLoad(rdm, category):23 pickUpData = []24 for i in range(len(rdm)):25 worksheet = get_sheet(category)26 col = worksheet.row_values(int(rdm[i]))27 newcol = ["None" if value=="" else value for value in col]28 pickUpData.append(newcol)29 print(pickUpData)30 return pickUpData 31 32class QuizView(discord.ui.View):33 def __init__(self, bot: commands.Bot,newcol):34 super().__init__(timeout=None)35 self.bot = bot 36 self.newcol = newcol 37 38 @discord.ui.button(label="hogebutton", style=discord.ButtonStyle.danger, custom_id="hoge_btn1")39 async def callback_quizbutton(self, button: discord.Button, interaction: discord.Interaction):40 await button.response.send_message("あなたはボタンを押しました")41 42class QuizCog(commands.Cog):43 def __init__(self,bot):44 self.bot = bot 45 46 @app_commands.command(name="aaaa", description="aaaaaa")47 async def quiz(self, interaction: discord.Interaction, category:str="問題", number:str="10"): 48 await interaction.response.send_message("読み込み中...")#,ephemeral=True49 rdm = random.sample(range(869),int(number))50 pickUpData = []51 loop = asyncio.get_event_loop()52 pickUpData = loop.run_in_executor(None, dataLoad, rdm, category)53 print(pickUpData)54 await interaction.followup.send(view=QuizView(self.bot,pickUpData))55 56async def setup(bot):57 await bot.add_cog(QuizCog(bot))58

0 コメント