---
# System prepended metadata

title: Untitled

---

```python
from discord import Client
import discord

import os

from google.cloud import texttospeech
from discord import FFmpegPCMAudio

with open("testbot_token.txt") as f:
    token = f.read()

client: Client = discord.Client()

#起動時処理
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "WebAPI.rtf"
gcp = texttospeech.TextToSpeechClient()
voice = texttospeech.types.VoiceSelectionParams(
           language_code='ja-JP',
           ssml_gender=texttospeech.enums.SsmlVoiceGender.NEUTRAL
           )
audio_config = texttospeech.types.AudioConfig(
                   audio_encoding=texttospeech.enums.AudioEncoding.MP3
                )

#各メッセージの処理
synthesis_input = texttospeech.types.SynthesisInput(text=text)
response = gcp.synthesize_speech(synthesis_input,
                                   voice,
                                   audioconfig)
binary_voice_data = response.audio_content

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_member_join(member):
    #システムメッセージchID
    channel = client.get_channel(635915059817611325)
    await channel.send(member.mention + ' プロデューサーさん、ようこそ!')

@client.event
async def on_message(message):

    if client.user in message.mentions and '通話来て' in message.content:
                                        #vcチャンネルID
        voicech = client.get_channel(635931392332791808)
        voice_client = await voicech.connect()
        """
        audio = FFmpegPCMAudio(binary_voice_data)
        voice_client.play(audio)
        """

    if client.user in message.mentions and 'おつかれ' in message.content:
        await message.guild.voice_client.disconnect()

@client.event
async def on_voice_state_update(member, before, after):
                        #監視するサーバーID
    if member.guild.id == 635912888208457768 and (before.channel != after.channel):
                                           #通知させるテキストchのID
        alert_channel = client.get_channel(635915209172582411)
        if before.channel is None:
            msg = member.mention + ' さんが通話に参加しました。'
            await alert_channel.send(msg)
        elif after.channel is None:
            msg = member.mention + ' さんが通話から退出しました。'
            await alert_channel.send(msg)

client.run(token)
```