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

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

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

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

Python

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

Q&A

解決済

1回答

2538閲覧

ディスコードbotコマンド反応しない

nkcpero

総合スコア0

Discord

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

Python

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

0グッド

0クリップ

投稿2021/10/04 05:58

編集2021/10/04 06:14
import discord from discord.ext import commands import asyncio import os import subprocess import ffmpeg from voice_generator import creat_WAV client = commands.Bot(command_prefix='.') voice_client = None @client.event async def on_ready(): print('Logged in as') print(client.user.name) print(client.user.id) print('------') @client.command() async def join(ctx): print('#join') print('#voicechannelを取得') vc = ctx.author.voice.channel print('#voicechannelに接続') await vc.connect() @client.command() async def bye(ctx): print('#bye') print('#切断') await ctx.voice_client.disconnect() @client.command() async def register(ctx, arg1, arg2): with open('C:/open_jtalk/bin/dic.txt', mode='a') as f: f.write('\n'+ arg1 + ',' + arg2) print('dic.txtに書き込み:''\n'+ arg1 + ',' + arg2) await ctx.send('`' + arg1+'` を `'+arg2+'` として登録しました') @client.event async def on_voice_state_update(member, before, after): server_id_test = "サーバーID" text_id_test = "チャンネルID" if member.guild.id == server_id_test: # サーバーid text_ch = client.get_channel(text_id_test) # 通知させたいTEXTチャンネルid if before.channel is None: msg = f'【VC参加ログ】{member.name} が {after.channel.name} に参加しました。' await text_ch.send(msg) @client.event async def on_message(message): print('---on_message_start---') msgclient = message.guild.voice_client print(msgclient) if message.content.startswith('.'): pass else: if message.guild.voice_client: print('#message.content:'+ message.content) creat_WAV(message.content) source = discord.FFmpegPCMAudio("output.wav") message.guild.voice_client.play(source) else: pass await client.process_commands(message) print('---on_message_end---') client.run("botのトークン") ``` ```### 前提・実現したいこと https://qiita.com/Nemy/items/d895114d3ba9a9d7cb62 上記のサイトを参考にディスコードでテキスト読み上げbotを作成しています。 ### 発生している問題・エラーメッセージ .joinと打ったらボイスチャンネルに入出するはずなのですが反応しません。 エラー None #join #voicechannelを取得 #voicechannelに接続 ---on_message_end--- Ignoring exception in command join: Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, i n wrapped ret = await coro(*args, **kwargs) File "C:\open_jtalk\bin\read_bot.py", line 27, in join await vc.connect() File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\abc.py", line 1277, in connect voice = cls(client, self) File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\voice_client.py", line 199, in __ init__ raise RuntimeError("PyNaCl library needed in order to use voice") RuntimeError: PyNaCl library needed in order to use voice The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, i n invoke await ctx.command.invoke(ctx) File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, i n wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: PyNaCl library needed in orde r to use voice ### 試したこと 権限の確認、botの再起動、再招待 ### 補足情報(FW/ツールのバージョンなど) 環境はWindows10、python3.7.9 上記のサイト通りに作成したのですがうまくいかなく困っています。どうぞよろしくお願い致します。

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

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

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

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

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

y_waiwai

2021/10/04 06:00

このままではコードが読めないので、質問を編集し、<code>ボタンを押し、出てくる’’’の枠の中にコードを貼り付けてください
1T2R3M4

2021/10/04 06:05

インデントをつけていないからでは。
guest

回答1

0

自己解決

"pip install PyNaCl"をコマンドプロンプトで実行したらコマンド反応しました。
PyNaClをインストールしてなかっただけでした。協力してくださった方ありがとうございました。

投稿2021/10/05 05:49

nkcpero

総合スコア0

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問