質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

360閲覧

意味がわからないエラーがでる

退会済みユーザー

退会済みユーザー

総合スコア0

Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/07/29 02:49

前提・実現したいこと

前提
なぜかjsonのdumpsの(?)エラーがでる。
実現したいこと
このエラーがでないように動かしたい。

発生している問題・エラーメッセージ

Traceback (most recent call last): File "C:\Users\programfile\discord\bots\new_bot\main_test.py", line 14, in <module> import discord File "C:\Users\matsu\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\__init__.py", line 25, in <module> from .client import Client File "C:\Users\matsu\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 33, in <module> import aiohttp File "C:\Users\matsu\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\__init__.py", line 6, in <module> from .client import ( File "C:\Users\matsu\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\client.py", line 35, in <module> from . import hdrs, http, payload File "C:\Users\matsu\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\http.py", line 6, in <module> from .http_exceptions import HttpProcessingError as HttpProcessingError File "C:\Users\matsu\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\http_exceptions.py", line 6, in <module> from .typedefs import _CIMultiDict File "C:\Users\matsu\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\typedefs.py", line 10, in <module> DEFAULT_JSON_ENCODER = json.dumps AttributeError: module 'json' has no attribute 'dumps'

該当のソースコード

python

1import asyncio 2import code 3import codecs 4import json 5import os 6import random 7import sys 8import textwrap 9import traceback 10from datetime import * 11from random import * 12from time import * 13 14import discord 15from discord import * 16from discord.ext import commands, tasks 17 18# from:python3 - m pip install dispander 19from dispander import * 20 21# 全cog 22cogs = ["cogs.call", "cogs.master", "cogs.sv"] 23 24 25def _bot(file_name="./json/bot.json"): 26 with open(file_name, "r") as f: 27 return json.load(f) 28 29 30# helpのクラス 31class Help(commands.HelpCommand): 32 def __init__(self): 33 super().__init__() 34 self.no_category = "カテゴリ未設定" 35 self.command_attrs["description"] = "このメッセージを表示します" 36 self.command_attrs["help"] = "botのコマンドリストをだします" 37 38 async def create_category_tree(self, category, enclosure): 39 """ 40 コマンドの集まり(Group、Cog)から木の枝状のコマンドリスト文字列を生成する 41 生成した文字列は enlosure 引数に渡された文字列で囲われる 42 """ 43 content = "" 44 command_list = category.walk_commands() 45 for cmd in await self.filter_commands(command_list, sort=True): 46 if cmd.root_parent: 47 # cmd.root_parent は「根」なので、根からの距離に応じてインデントを増やす 48 index = cmd.parents.index(cmd.root_parent) 49 indent = "\t" * (index + 1) 50 if indent: 51 content += f"{indent}- {cmd.name} / {cmd.description}\n" 52 else: 53 # インデントが入らない、つまり木の中で最も浅く表示されるのでprefixを付加 54 content += f"{self.context.prefix}{cmd.name} / {cmd.description}\n" 55 else: 56 # 親を持たないコマンドなので、木の中で最も浅く表示する。prefixを付加 57 content += f"{self.context.prefix}{cmd.name} / {cmd.description}\n" 58 59 return enclosure + textwrap.dedent(content) + enclosure 60 61 async def send_bot_help(self, mapping): 62 embed = discord.Embed(title="helpコマンド", color=0x00FF00) 63 if self.context.bot.description: 64 # もしBOTに description 属性が定義されているなら、それも埋め込みに追加する 65 embed.description = self.context.bot.description 66 for cog in mapping: 67 if cog: 68 cog_name = cog.qualified_name 69 else: 70 # mappingのキーはNoneになる可能性もある 71 # もしキーがNoneなら、自身のno_category属性を参照する 72 cog_name = self.no_category 73 74 command_list = await self.filter_commands(mapping[cog], sort=True) 75 content = "" 76 for cmd in command_list: 77 content += f"`{self.context.prefix}{cmd.name}`\n {cmd.description}\n" 78 embed.add_field(name=cog_name, value=content, inline=True) 79 80 await self.get_destination().send(embed=embed) 81 82 async def send_cog_help(self, cog): 83 embed = discord.Embed( 84 title=cog.qualified_name, description=cog.description, color=0x00FF00 85 ) 86 embed.add_field( 87 name="コマンドリスト:", value=await self.create_category_tree(cog, "```") 88 ) 89 await self.get_destination().send(embed=embed) 90 91 async def send_group_help(self, group): 92 embed = discord.Embed( 93 title=f"{self.context.prefix}{group.qualified_name}", 94 description=group.description, 95 color=0x00FF00, 96 ) 97 if group.aliases: 98 embed.add_field( 99 name="有効なエイリアス:", 100 value="`" + "`, `".join(group.aliases) + "`", 101 inline=False, 102 ) 103 if group.help: 104 embed.add_field(name="ヘルプテキスト:", value=group.help, inline=False) 105 embed.add_field( 106 name="サブコマンドリスト:", 107 value=await self.create_category_tree(group, "```"), 108 inline=False, 109 ) 110 await self.get_destination().send(embed=embed) 111 112 async def send_command_help(self, command): 113 params = " ".join(command.clean_params.keys()) 114 embed = discord.Embed( 115 title=f"{self.context.prefix}{command.qualified_name} {params}", 116 description=command.description, 117 color=0x00FF00, 118 ) 119 if command.aliases: 120 embed.add_field( 121 name="有効なエイリアス:", 122 value="`" + "`, `".join(command.aliases) + "`", 123 inline=False, 124 ) 125 if command.help: 126 embed.add_field(name="ヘルプテキスト:", value=command.help, inline=False) 127 await self.get_destination().send(embed=embed) 128 129 async def send_error_message(self, error): 130 embed = discord.Embed(title="ヘルプ表示のエラー", description=error, color=0xFF0000) 131 await self.get_destination().send(embed=embed) 132 133 def command_not_found(self, string): 134 return f"{string} というコマンドは存在しません。" 135 136 def subcommand_not_found(self, command, string): 137 if isinstance(command, commands.Group) and len(command.all_commands) > 0: 138 # もし、そのコマンドにサブコマンドが存在しているなら 139 return f"{command.qualified_name}{string} というサブコマンドは登録されていません" 140 return f"{command.qualified_name} にサブコマンドは登録されていません" 141 142 143# メインクラス 144class raitokun(commands.Bot): 145 """ 146 JA:メインです 147 EN:main 148 """ 149 150 # raitokunのコンストラクタ 151 def __init__(self, command_prefix, help_command, intents): 152 # スーパークラスのコンストラクタに値を渡して実行 153 super().__init__( 154 command_prefix, 155 case_insensitive=True, 156 help_command=help_command, 157 intents=intents, 158 ) 159 160 self.notice = 867059273204367421 # おいらのサーバーのID 161 self.token = _bot["token"] # tokenの読み取り 162 163 for cog in cogs: 164 try: 165 self.load_extension(cog, "dispander") 166 except Exception as e: 167 self.failure(e) 168 169 def failure(self, e): 170 exc_type, exc_obj, exc_tb = sys.exc_info() 171 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] 172 print(f"\n{e}|{fname}|{exc_tb.tb_lineno}|{type(e)}\n") 173 174 # ----------------------------------------- bot event's ----------------------------------------- 175 176 # 起動時 177 @bot.event 178 async def on_ready(self): 179 print("ok") 180 dt = datetime.now() 181 now = dt.strftime("%m月%d日 %H:%M") 182 channel = bot.get_channel(notice) 183 embed = discord.Embed(title="ログイン通知\nログインしました") 184 embed.add_field(name="ログイン日時", value=str(now), inline=False) 185 await channel.send(embed=embed) 186 187 # botのステータス 188 @tasks.loop(seconds=30) 189 async def change_activity(self): 190 await bot.change_presence( 191 activity=discord.Game(name=f"ぼちぼち開発中\n鯖参加数:{len(bot.guilds)}サーバー入ってます!!") 192 ) 193 194 @change_activity.before_loop 195 async def before_change_activity(self): 196 await bot.wait_until_ready() 197 198 change_activity.start() 199 200 # 鯖参加情報 201 @bot.event 202 async def on_guild_join(self, guild): 203 try: 204 channel = bot.get_channel(notice) 205 embed = discord.Embed(title="サーバー参加通知", color=discord.Colour.gold()) 206 embed.add_field(name="鯖名", value=guild.name) 207 embed.add_field(name="鯖ID", value=guild.id) 208 await channel.send(embed=embed) 209 except Exception as e: 210 try: 211 await channel.send(str(e)) 212 except: 213 print(str(e)) 214 bot.get_guild(guild.id) 215 216 # ----------------------------------------- bot event's end ----------------------------------------- 217 218 def run(self): 219 super().run(self.token, reconnect=True) 220 221 222bot = raitokun(command_prefix="", help_command=Help(), intents=discord.Intents.all()) 223 224 225if __name__ == "__main__": 226 raito = raitokun() 227 raito.run() 228

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

json.py を作っていませんか?
名前を変えてみて下さい。

投稿2021/07/29 03:02

sevenc-nanashi

総合スコア643

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

エラーのでる環境で、以下を実行してみてください。

python

1import json 2print(json)

これで表示される中に、json.pyかjson/init.pyがあると思います。
その名前が標準モジュールjsonの名前とバッティングしているので、名前を変更すればエラーは出なくなります。

投稿2021/07/29 03:01

ppaul

総合スコア24666

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問