前提
ここに質問の内容を詳しく書いてください。
slashコマンドや、button機能を使いたく、バージョンを2.0.0にしました。
その中で、Botを起動し動くか確認したとこ、コマンドどころか prefixすら反応しんくなりました。
解決方法を教えてください。
実現したいこと
・コマンドに反応するようにする。
・prefixが反応するようにする。
発生している問題・エラーメッセージ
表示されません。
該当のソースコード
python
import asyncio import datetime import os import traceback import discord from discord.ext import commands from dotenv import load_dotenv from help_command import HelpCommand now = datetime.datetime.now() load_dotenv() TOKEN = os.environ["TOKEN"] NOTICE = チャンネルID class MatsuochinyuBot(commands.Bot): def __init__(self, command_prefix, intents, help_command): super().__init__(command_prefix=command_prefix, intents=intents, help_command=help_command) self.success = 0 self.failure = 0 self.filename = [file.replace(".py", "") for file in os.listdir("./cogs") if file.endswith(".py")] async def load_extensions(self): print("Cogを読み込みます") for filename in self.filename: print("-" * 10) print(filename) try: await self.load_extension(f"cogs.{filename}") print(f"Read success:{filename}") self.success += 1 except Exception as e: print(e) print(f"Read failure:{filename}") self.failure += 1 print("-" * 10) print(f"成功:{self.success} 失敗:{self.failure}\n") async def on_ready(self): embed = discord.Embed(title="Info", description="", color=0x00FF00) embed.add_field(name="Cogの読み込み", value=f"成功:{self.success} 失敗:{self.failure}") await self.get_channel(NOTICE).send(embed=embed) with open("cogs/reload.txt", "r", encoding="utf-8") as f: read_file = f.read() if read_file == "": pass else: await self.get_channel(int(read_file)).send( "``loading...``", delete_after=3 ) embed = discord.Embed( title="___リロード完了通知___", description="使えるようになりました。", color=0x00FF00 ) await self.get_channel(int(read_file)).send(embed=embed, delete_after=3) with open("cogs/reload.txt", "w", encoding="utf-8") as f: f.write("") async def on_command_error(self, ctx, error): """すべてのコマンドで発生したエラーを拾う""" if isinstance(error, commands.CommandInvokeError): orig_error = getattr(error, "original", error) error_msg = "".join( traceback.TracebackException.from_exception(orig_error).format() ) error_message = f"```{error_msg}```" ch = ctx.guild.get_channel(NOTICE) embed = discord.Embed( title="エラーログ", description=error_message, color=0xF04747 ) embed.set_footer( text=f"Time:{now:%Y-%m-%d %H:%M:%S}\nGuild:{ctx.guild}\nChannel:{ctx.channel}\nUser:{ctx.author.display_name} " ) await ch.send(embed=embed) # Botの設定 intent = discord.Intents.default() intent.typing = False intent.members = True intent.messages = True bot = MatsuochinyuBot( command_prefix=commands.when_mentioned_or("m:"), intents=intent, help_command=HelpCommand(), ) # ログイン処理 async def main(): async with bot: await bot.load_extensions() await bot.start(TOKEN) if __name__ == "__main__": print("ログイン中...\n") print(f"Information's:{datetime.datetime.now()}") print("-" * 40) print(f"Discord.py Version:{discord.__version__}") print("-" * 40) print("ログイン完了\n") asyncio.run(main())
試したこと
色々なネット記事を参考にして試みてみましたが、動きませんでした。
補足情報(FW/ツールのバージョンなど)
discord.py:Version: 2.0.0a4058+gabeea73
python:3.9.12
mac OS:catalina 10.15.7
まだ回答がついていません
会員登録して回答してみよう