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

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

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

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

2回答

5911閲覧

glitchでjavascriptではなくpythonのdiscordのbotを動かしたい(discord.pyを使いたい)

kei0005

総合スコア19

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

1グッド

0クリップ

投稿2021/02/06 00:28

前提・実現したいこと

当方プログラミングの初心者です。

glitchを用いてdiscordのbotを作りたいと考えています。
後々スクレイピング等の機能も実装できるのか試してみたい都合上、javascriptではなくpythonを用いてbotを動かしたいと考えています。

後半の方にも記載しているのですが、discord.pyのdiscordフォルダをglitchにアップロードできないためモジュールが見つからず起動できていないのだと思われます。

こちらのサイトhttps://qiita.com/1ntegrale9/items/9d570ef8175cf178468f
を参考にしています。

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

1つ目にエラーメッセージ全文を、2つ目にエラーメッセージの特に重要そうな部分だけ抜き出したものを表示します

node v12.0.0, with pnpm Installing... Performing headless installation > hello-express@0.0.1 install /app > pip3 install --force-reinstall -r ./requirements.txt Defaulting to user installation because normal site-packages is not writeable ERROR: Could not open requirements file: [Errno 2] No such file or directory: './requirements.txt' ERROR  hello-express@0.0.1 install: `pip3 install --force-reinstall -r ./requirements.txt` Exit status 1 at Error: hello-express at <anonymous> /opt/nvm/versions/node/v10.23.0/lib/node_modules/pnpm/lib/node_modules/@zkochan/npm-lifecycle/index.js:303 var er = new Error('Exit… at emit events.js:196 at <anonymous> /opt/nvm/versions/node/v10.23.0/lib/node_modules/pnpm/lib/node_modules/@zkochan/npm-lifecycle/lib/spawn.js:55 cooked.emit('close', cod… at emit events.js:196 at maybeClose internal/child_process.js:1000 at onexit internal/child_process.js:267 Traceback (most recent call last): File "server.py", line 8, in <module> client = discord.Client() AttributeError: module 'discord' has no attribute 'Client' File "server.py", line 5 #import urllib.request ^ SyntaxError: invalid character in identifier Traceback (most recent call last): File "server.py", line 8, in <module> client = discord.Client() AttributeError: module 'discord' has no attribute 'Client' Traceback (most recent call last): File "server.py", line 6, in <module> from discord.ext import commands ModuleNotFoundError: No module named 'discord.ext'

エラーメッセージ抜粋

ERROR: Could not open requirements file: [Errno 2] No such file or directory: './requirements.txt' Traceback (most recent call last): File "server.py", line 8, in <module> client = discord.Client() AttributeError: module 'discord' has no attribute 'Client' Traceback (most recent call last): File "server.py", line 6, in <module> from discord.ext import commands ModuleNotFoundError: No module named 'discord.ext'

該当のソースコード

json

1//package.json 2//汚くて申し訳ないです 3{ 4 "//1": "describes your app and its dependencies", 5 "//2": "https://docs.npmjs.com/files/package.json", 6 "//3": "updating this file will download and update your packages", 7 "install": "pip3 install -U discord.py", 8 "install": "pip3 install --force-reinstall -r ./requirements.txt", 9 "name": "hello-express", 10 "version": "0.0.1", 11 "description": "A simple Node app built on Express, instantly up and running.", 12//server.js → server.pyに変えています 13 "main": "server.py",  14 "scripts": { 15 "install": "pip3 install -U discord.py", 16 "install": "pip3 install --force-reinstall -r ./requirements.txt", 17 "start": "python3 server.py" 18 }, 19 "dependencies": { 20 "express": "^4.17.1", 21 "discord.js": "^11.6.4", 22 "querystring": "^0.2.0" 23 }, 24 "engines": { 25 "node": "12.x" 26 }, 27 "repository": { 28 "url": "https://glitch.com/edit/#!/hello-express" 29 }, 30 "license": "MIT", 31 "keywords": [ 32 "node", 33 "glitch", 34 "express" 35 ] 36}

python

1import asyncio 2import json 3import re 4import discord 5from discord.ext import commands 6 7client = discord.Client() 8 9# 起動時に動作する処理 10@client.event 11async def on_ready(): 12 # 起動したらターミナルにログイン通知が表示される 13 print('ログインしました') 14 15# メッセージ受信時に動作する処理 16@client.event 17async def on_message(message): 18 # メッセージ送信者がBotだった場合は無視する 19 if message.author.bot: 20 return 21 # 「/neko」と発言したら「にゃーん」が返る処理 22 if message.content == '/neko': 23 await message.channel.send('にゃーん') 24 25# Botの起動とDiscordサーバーへの接続 26#.envファイルで DISCORD_BOT_TOKEN = (ボットトークンのID)を設定しています 27client.run(DISCORD_BOT_TOKEN)

試したこと

エラー内容からdiscord.py(https://github.com/Rapptz/discord.py)がglitchサーバ上に存在していないためエラーが発生していると思われるのですが、discordフォルダをそのままアップロードできないためそのままではエラーを解決できずにいます。

長くなってしまいましたが、
①glitch上でjavascriptではなくpythonを動かしてdiscordのbotを動かしたい
②glitchにフォルダをアップロードできず、ローカル上で出来たフォルダ構成がそのままでは再現出来ない

に困っております。

naisu👍を押しています

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

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

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

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

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

guest

回答2

0

glitchでdiscord.pyを動作させるためには、少し工夫が必要です。
僕が作成したdiscord-botのテンプレートを張っておきます。
https://glitch.com/edit/#!/discord-python-test

python

1import discord 2import os 3#略 4client.run(os.getenv('TOKEN'))

このコードでimport osos.getenv("TOKEN")は必須です。
これがなければ.envファイルから情報が取れません。
あとはremixしてあなたの思い通りのコードを書いてください。
discordのbot作り、応援しています。

投稿2021/04/14 14:13

編集2023/07/06 13:20
yaakiyu01

総合スコア68

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

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

0

ERROR: Could not open requirements file: [Errno 2] No such file or directory: './requirements.txt'

requirements.txt が存在しないようです。確認してみてください。
あと、これは直接的には関係ないと思いますが、

"dependencies": {
"express": "^4.17.1",
"discord.js": "^11.6.4",
"querystring": "^0.2.0"
},
"engines": {
"node": "12.x"
},

この部分は不要です。
というかGlitchのPython3は地味に古かった気が···

投稿2022/01/02 16:39

Awayume

総合スコア60

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問