実現したいこと
botをボイスチャットに参加させたい
前提
ここに質問の内容を詳しく書いてください。
前に作ったコマンドを
discord.py (2.0)を使ってスラッシュコマンドをに対応させています!
発生している問題・エラーメッセージ
discord.app_commands.errors.CommandInvokeError: Command 'join' raised an exception: AttributeError: 'Interaction' object has no attribute 'author'
該当のソースコード
python
1 2import discord 3from discord.ext import commands 4from discord import app_commands 5 6bot = commands.Bot( 7 command_prefix=config['prefix'], 8 help_command=None, 9 case_insensitive=True, 10 intents=Intents 11 ) 12 13@bot.event 14async def on_ready(): 15 print("起動完了") 16 #ステータスの変更 17 await bot.change_presence(activity=discord.Game(name="testモードで起動中")) 18 try: 19 synced = await bot.tree.sync(guild=My_guild)#スラッシュコマンドを同期 20 print(f"コマンドが{len(synced)}個登録されています") 21 22 except Exception as e: 23 print(e) 24 25@bot.tree.command(name = "join" , description= "ボイスチャットに参加します",guild=My_guild) 26async def testjoin(interaction: discord.VoiceChannel): 27 await interaction.response.defer(ephemeral=True) 28 if interaction.author.voice == None: 29 await interaction.send("ボイスチャンネルに参加していません") 30 return 31 if interaction.voice_client == None: 32 await interaction.author.voice.channel.connect() 33 await interaction.send("ボイスチャンネルに接続しました") 34 else: 35 await interaction.voice_client.move_to(interaction.author.voice.channel)
補足情報(FW/ツールのバージョンなど)
discord.py 2.2.2
python 3.10
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/05/09 12:30