前提
discord.pyでBotを作っています。
pip install -U git+https://github.com/Rapptz/discord.py
と入力し、discord.pyを最新のバージョンにしたら使えなくなりました。
実現したいこと
・意味不明のエラーを無くして動くようにする
発生している問題・エラーメッセージ
Traceback (most recent call last): File "/Users/matsuochinyu/home/workspace/Discord/main.py", line 119, in <module> bot.run(TOKEN) File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 709, in run asyncio.run(runner()) File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete return future.result() File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 706, in runner await self.start(*args, **kwargs) File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 680, in start await self.connect(reconnect=reconnect) File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 617, in connect raise PrivilegedIntentsRequired(exc.shard_id) from None discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
該当のソースコード
python
1import datetime 2import json 3import os 4import traceback 5 6import discord 7from discord.ext import commands 8from dotenv import load_dotenv 9 10from help_command import HelpCommand 11 12now = datetime.datetime.now() 13load_dotenv() 14TOKEN = os.environ["TOKEN"] 15INITIAL_EXTENSIONS = [ 16 f"cogs.{file}".replace(".py", "") 17 for file in os.listdir("cogs") 18 if file.endswith("py") 19] 20NOTICE = CHANNEL_ID 21 22 23class Bot(commands.Bot): 24 def __init__(self, command_prefix, intents, help_command): 25 super().__init__(command_prefix, intents=intents, help_command=help_command) 26 27 print("Cogを読み込みます") 28 self.success = 0 29 self.failure = 0 30 for cog in INITIAL_EXTENSIONS: 31 print("-" * 10) 32 print(cog) 33 try: 34 self.load_extension(cog) 35 print(f"Read success:{cog}") 36 self.success += 1 37 except Exception as e: 38 print(e) 39 print(f"Read failure:{cog}") 40 self.failure += 1 41 print("-" * 10) 42 print(f"成功:{self.success} 失敗:{self.failure}\n") 43 44 async def on_ready(self): 45 embed = discord.Embed(title="Info", description="", color=0x00FF00) 46 embed.add_field(name="Cogの読み込み", value=f"成功:{self.success} 失敗:{self.failure}") 47 await self.get_channel(NOTICE).send(embed=embed) 48 49 with open("cogs/reload.txt", "r", encoding="utf-8") as f: 50 read_file = f.read() 51 if read_file == "": 52 pass 53 else: 54 await self.get_channel(int(read_file)).send( 55 "``loading...``", delete_after=3 56 ) 57 embed = discord.Embed( 58 title="___リロード完了通知___", description="使えるようになりました。", color=0x00FF00 59 ) 60 await self.get_channel(int(read_file)).send(embed=embed, delete_after=3) 61 with open("cogs/reload.txt", "w", encoding="utf-8") as f: 62 f.write("") 63 64 async def on_command_error(self, ctx, error): 65 """すべてのコマンドで発生したエラーを拾う""" 66 if isinstance(error, commands.CommandInvokeError): 67 orig_error = getattr(error, "original", error) 68 error_msg = "".join( 69 traceback.TracebackException.from_exception(orig_error).format() 70 ) 71 error_message = f"```{error_msg}```" 72 73 ch = ctx.guild.get_channel(NOTICE) 74 embed = discord.Embed( 75 title="エラーログ", description=error_message, color=0xF04747 76 ) 77 embed.set_footer( 78 text=f"Time:{now:%Y-%m-%d %H:%M:%S}\nGuild:{ctx.guild}\nChannel:{ctx.channel}\nUser:{ctx.author.display_name}" 79 ) 80 await ch.send(embed=embed) 81 82if __name__ == "__main__": 83 intent = discord.Intents.all() 84 intent.typing = True 85 intent.members = True 86 intent.messages = True 87 intent.reactions = True 88 89 print("ログイン中...\n") 90 bot = Bot( 91 command_prefix=commands.when_mentioned_or("m:"), 92 intents=intent, 93 help_command=HelpCommand(), 94 ) 95 96 print(f"Informations:{datetime.datetime.now()}") 97 print("-" * 40) 98 print(f"Discord.py Version:{discord.__version__}") 99 print(bot.author.display_name) 100 print(bot.author.id) 101 print("-" * 40) 102 print("ログイン完了\n") 103 bot.run(TOKEN)
補足情報(FW/ツールのバージョンなど)
・MacBook Pro(Retina 15Inch, Early 2013)
・MacOS:Catalina 10.15.7
・discord.py:Version: 2.0.0a4000+g8a222b6
・シェル:Zsh
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。