Last active
May 18, 2022 11:13
-
-
Save khlizard/c92770a2c315d471560687b23d566a81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""minimum_rtsp_bot.py | |
- 指定したRTSPストリームをプレイするだけのbotです | |
- DiscordのどこかのVoiceChに入った状態で '!playstream' とすると、そのchに入ってきてストリームを流し始めます | |
- 再生中に '!stopstream' とすると、再生を停止してvoice chからも抜けます | |
- 再生中に '!resyncstream' で再接続します | |
- 必要なパッケージは(多分)discord.py・discord.py[voice]・pynacl、あとffmpegがパスの通ってるところに必要だと思います | |
- botのTOKENの取得は https://qiita.com/1ntegrale9/items/cb285053f2fa5d0cccdf を参考にして下さい | |
""" | |
import os | |
import discord | |
from discord.channel import VoiceChannel | |
from discord.player import FFmpegPCMAudio | |
TOKEN = os.environ['DISCORD_BOT_TOKEN'] | |
streamURL = 'rtsp://example.com/live/foobar9823' | |
client = discord.Client() | |
voiceCh: VoiceChannel = None | |
@client.event | |
async def on_ready(): | |
print('login discord server.') | |
@client.event | |
async def on_message(message): | |
global voiceCh | |
if message.author.bot: | |
return | |
if message.content == '!playstream': | |
if voiceCh is None and message.author.voice is not None: | |
voiceCh = await VoiceChannel.connect(message.author.voice.channel) | |
voiceCh.play(FFmpegPCMAudio(streamURL)) | |
await message.channel.send('Streamを再生します') | |
return | |
if message.content == '!resyncstream': | |
if voiceCh is not None: | |
voiceCh.stop() | |
voiceCh.play(FFmpegPCMAudio(streamURL)) | |
await message.channel.send('Resyncします') | |
return | |
if message.content == '!stopstream': | |
if voiceCh is not None: | |
voiceCh.stop() | |
await voiceCh.disconnect() | |
voiceCh = None | |
await message.channel.send('再生を終了します') | |
return | |
client.run(TOKEN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment