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

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

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

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

Python 3.x

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

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Q&A

解決済

1回答

1354閲覧

heroku対応のdiscord botに音楽を流すコマンドを知りたい

Libe

総合スコア13

Discord

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

Python 3.x

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

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

0グッド

0クリップ

投稿2021/10/09 14:06

編集2021/10/11 01:22

やりたいこと
heroku対応discord bot music機能を作りたい

調べてみましたがyoutube-dl,ffmpegが使えません

herokuはgithubで繋いでます
ディレクトリ構成

Github |--cogs | |--_init_.py | |---LibeCog2.py | |---music.py | LibeCog.py main.py

開発環境

python-3.9.5 discord.py=1.7.3

main.py

python

1from discord.ext import commands 2import traceback 3import discord 4from datetime import datetime, timedelta 5import datetime 6 7INITIAL_EXTENSIONS = ['cogs.LibeCog','cogs.LibeCog2','cogs.music'] 8 9now = datetime.datetime.now() 10 11# コグとして用いるクラスを定義。 12 13 14class LibeBot(commands.Bot): 15 def __init__(self, command_prefix): 16 # スーパークラスのコンストラクタに値を渡して実行。 17 super().__init__(command_prefix) 18 19 # INITIAL_COGSに格納されている名前から、コグを読み込む。 20 # エラーが発生した場合は、エラー内容を表示。 21 for cog in INITIAL_EXTENSIONS: 22 try: 23 self.load_extension(cog) 24 except Exception: 25 traceback.print_exc() 26 27 28 29 30 async def on_ready(self): 31 print('--------------------------------------') 32 print('Logged on as {0}!'.format(self.user)) 33 print('--------------------------------------') 34 print(self.user.id) 35 print('--------------------------------------') 36 print('ログインしました。') 37 print('--------------------------------------') 38 print(now.date()) 39 print('--------------------------------------') 40 print('discord.pyバージョン',discord.__version__) 41 print('--------------------------------------') 42 43if __name__ == '__main__': 44 bot = LibeBot(command_prefix='.') 45 bot.run('TOKEN')

LibeCog.py

python

1import discord 2import logging 3import abc 4import requests 5from discord.ext import tasks, commands 6import aiohttp 7from pprint import pprint 8import asyncio 9import json 10import typing 11import traceback 12import random 13import time 14import re 15from discord.ext import commands 16from datetime import datetime, timedelta 17import datetime 18import sys 19from pytz import timezone 20import socket 21 22 23now = datetime.datetime.now() 24 25intents = discord.Intents.all() 26 27CHANNEL_ID = 845440592258662433 28 29host = socket.gethostname() 30print('--------------------------------------') 31print(host) 32 33# ipアドレスを取得、表示 34ip = socket.gethostbyname(host) 35print('--------------------------------------') 36print("IPアドレス",ip) 37 38# コグとして用いるクラスを定義。 39class LibeCog(commands.Cog): 40 41 @commands.command() 42 async def k(self, ctx): 43 async with ctx.typing(): 44 await asyncio.sleep(4) 45 await ctx.send("https://c.tenor.com/Jt0VfYbpyAoAAAAC/%E3%82%AD%E3%82%BA%E3%83%8A%E3%82%A2%E3%82%A4-kizuna-ai.gif") 46 print("年",now.year,"月",now.month,"日",now.day,) 47 48 @commands.command() 49 async def typing(self, ctx): 50 async with ctx.typing(): # 送られてきたチャンネルで入力中と表示させる 51 await asyncio.sleep(3) # 重い処理をwith内で書く。(一例) 52 await ctx.send("?") 53 54 @commands.command() 55 async def gg(self, ctx): 56 await ctx.send("https://storage.googleapis.com/support-forums-api/attachment/message-119416521-7110180789076656037.gif") 57 58 @commands.command() 59 async def bbf(self, ctx): 60 await ctx.send("https://thumbs.gfycat.com/AcademicAffectionateFoal-size_restricted.gif") 61 62 @commands.command() 63 async def hiroyuki(self, ctx): 64 await ctx.send("http://livedoor.blogimg.jp/source_2ch/imgs/9/7/971eec30.gif") 65 66 @commands.command() 67 async def hiroyuki1(self, ctx): 68 await ctx.send("https://up.gc-img.net/post_img/2021/06/p4JCYlTEdYbcpMF_S3lMY_193.gif") 69 70def setup(bot): 71 print('--------------------------------------------------') 72 print('LibeCogファイルを読み込んだよ!') 73 bot.add_cog(LibeCog(bot))

LibeCog2.py

python

1from discord.ext import tasks, commands 2import discord 3import logging 4import abc 5import requests 6import aiohttp 7from pprint import pprint 8import asyncio 9import json 10import typing 11import traceback 12import random 13import time 14import re 15from discord.ext import commands 16from datetime import datetime, timedelta 17import datetime 18import sys 19from pytz import timezone 20import socket 21from icrawler.builtin import GoogleImageCrawler 22 23now = datetime.datetime.now() 24 25intents = discord.Intents.all() 26 27 28CHANNEL_ID = 845440592258662433 29 30random_contents_Marsh = [ 31 "https://biz-journal.jp/images/post_13572_20160131.jpg", 32] 33 34 35 36 37 38 39 40 41class LibeCog2(commands.Cog): 42 43 @commands.Cog.listener() 44 async def on_message(self, message): 45 46 print('メッセージが来たよ→ {0.author}: {0.content}'.format(message)) 47 48 49 50 if message.content.startswith('/id'): 51 await message.channel.send('PaL_Libe') 52 53 if message.content == '!bot': 54 await message.channel.send('```BOT discordバージョン起動中です。```') 55 56 if message.content.startswith('Hi'): 57 await message.channel.send(message.author.mention + 'こんちゃーす') 58 59 if message.content.startswith('/nhk'): 60 await message.channel.send( 61 message.author.mention + 62 'https://gendai.ismedia.jp/mwimgs/2/7/-/img_27d1ecc00191cbbf4d98e1129f2399f544134.jpg' 63 ) 64 65 if message.content.startswith('/2'): 66 await message.channel.send( 67 message.author.mention + 68 'https://img.huffingtonpost.com/asset/5c6389752300007601224077.jpeg?ops=1200_630' 69 ) 70 71 72 if message.content.startswith('/日にち'): 73 await message.channel.send(f"```{now.date()}です。```") 74 75 if message.content.startswith('/clean'): 76 await message.channel.purge() 77 await message.channel.send('????✡????????☼✡⚐????????✋????✌????✋❄✌') 78 79 if message.channel.id != CHANNEL_ID: # チャンネルが違う場合は無視する 80 return 81 82 if message.content == '/k9': 83 await message.channel.send('https://www.animatetimes.com/news/details.php?id=1592974623') 84 await asyncio.sleep(2) 85 await message.channel.send('https://news.cos-lab.com/wp-content/uploads/2018/08/hiEp1H7KWX.jpg') 86 await asyncio.sleep(2) 87 await message.channel.send('https://images-fe.ssl-images-amazon.com/images/I/51US4E54Y4L.jpg') 88 await asyncio.sleep(2) 89 await message.channel.send('https://contents.oricon.co.jp/upimg/news/20180807/2117032_201808070014772001533592817c.jpg') 90 await asyncio.sleep(2) 91 await message.channel.send('https://news.cos-lab.com/wp-content/uploads/2017/12/86f2a39154e57c2a1b63922da65f2306_great_cosplayer.jpg') 92 await asyncio.sleep(2) 93 await message.channel.send('https://news.cos-lab.com/wp-content/uploads/2017/12/16c737a917905d48173f91bf03e720b3_great_cosplayer.jpg') 94 await asyncio.sleep(2) 95 await message.channel.send('https://livedoor.blogimg.jp/asagawoblog/imgs/1/c/1c736813.jpg') 96 await asyncio.sleep(2) 97 await message.channel.send('https://news.cos-lab.com/wp-content/uploads/2017/12/437b8c7e296992f8d1466c04ac5b1aff_great_cosplayer.jpg') 98 await asyncio.sleep(5) 99 await message.channel.send('情報漏洩防止の為この情報は一分で削除します') 100 await asyncio.sleep(60) 101 await message.channel.purge() 102 await asyncio.sleep(3) 103 await message.channel.send('削除が完了しました。') 104 105 if message.content == "/k92": 106 content = random.choice(random_contents_Marsh) 107 await message.channel.send(content) 108 109 110def setup(bot): 111 print('--------------------------------------------------') 112 print('LibeCog2ファイルを読み込んだよ!') 113 bot.add_cog(LibeCog2(bot))

music.py

python

1from discord.ext import tasks, commands 2import discord 3import logging 4import abc 5import requests 6import aiohttp 7from pprint import pprint 8import asyncio 9import json 10import typing 11import traceback 12import random 13import time 14import re 15from discord.ext import commands 16from datetime import datetime, timedelta 17import datetime 18import sys 19from pytz import timezone 20import socket 21from icrawler.builtin import GoogleImageCrawler 22 23 24 25#client = discord.Client() 26 27 28 29 30class LibeMusic(commands.Cog): 31 32 33 34 35 @commands.Cog.listener() 36 async def on_message(self, message): 37 38 if message.content == "!join": 39 if message.author.voice is None: 40 await message.channel.send("あなたはボイスチャンネルに接続していません。") 41 return 42 # ボイスチャンネルに接続する 43 await message.author.voice.channel.connect() 44 await message.channel.send("接続しました。") 45 46 elif message.content == "!leave": 47 if message.guild.voice_client is None: 48 await message.channel.send("接続していません。") 49 return 50 51 # 切断する 52 await message.guild.voice_client.disconnect() 53 54 await message.channel.send("切断しました。") 55 56 57 58def setup(bot): 59 print('--------------------------------------------------') 60 print('LibeMusicファイルを読み込んだよ!') 61 bot.add_cog(LibeMusic(bot))

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

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

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

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

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

guest

回答1

0

自己解決

調べたら解決しました

投稿2021/10/17 00:11

Libe

総合スコア13

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問