Skip to content

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
asdkmm5050 committed Jul 6, 2022
1 parent dde44bf commit 150a169
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.8

RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get install -y ffmpeg

COPY ./audio.py /app/
COPY ./bot.py /app/
COPY ./config.json /app/
WORKDIR /app
RUN pip install discord
RUN pip install discord-py-slash-command==3.0.3
RUN pip install gTTs
RUN pip install ffmpeg
RUN pip install PyNaCl
CMD python ./bot.py
8 changes: 4 additions & 4 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
- 這是一個 Discord TTS 機器人,可以加入語音頻道並幫你說話。

### 需要
- discord
- discord_slash
- ffmpeg(like C:\fffmpeg\bin\fffmpeg.exe)
- docker

### 怎麼用

Expand All @@ -19,7 +17,9 @@
"token":"your token"
}
```
- 執行 python ./bot.py
- 執行
- ```docker build -t "your image name" .```
- ```docker run "your image name"```

### 命令
- `/join`
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
- This is a Discord TTS bot, let it join a voice channel and speak for you.

### Need
- discord
- discord_slash
- ffmpeg(like C:\fffmpeg\bin\fffmpeg.exe)
- docker

### How to use

- add a config.json file under ./
- add a config.json file in ./
```
{
"token":"your token"
}
```
- run python ./bot.py
- run
- ```docker build -t "your image name" .```
- ```docker run "your image name"```

### Commands
- `/join`
Expand All @@ -30,4 +29,4 @@
### Bot link
- [Bot](https://discord.com/api/oauth2/authorize?client_id=949268140267806743&permissions=2150639616&scope=bot%20applications.commands)
- **I can see all the messages sent by this bot.**
- The server is hosted on my own computer, may turn off anytime.
- The server is hosted on my own computer, may turn off anytime.
3 changes: 3 additions & 0 deletions audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ def __init__(self, text, channel, language):

def saveAudio(self, channel):
self.output.save(f'./audio/{channel}.mp3')

def getAudio(self):
return self.output
5 changes: 3 additions & 2 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import asyncio
import re

import os

# ctx為context的縮寫

Expand Down Expand Up @@ -56,7 +56,7 @@ async def playAudio(self, channel):
Audio(message, channel, self.languageList[channel])
print(message, 'task start talking...')
self.ctx[channel].voice_client.play(
discord.FFmpegPCMAudio(executable='C:/ffmpeg/bin/ffmpeg.exe', source=f'./audio/{channel}.mp3'))
discord.FFmpegPCMAudio(source=f'./audio/{channel}.mp3'))

while self.ctx[channel].voice_client.is_playing():
await asyncio.sleep(0.1)
Expand Down Expand Up @@ -161,4 +161,5 @@ async def on_ready():


if __name__ == '__main__':
os.mkdir("audio")
main()

0 comments on commit 150a169

Please sign in to comment.