LoginSignup
0
0

More than 3 years have passed since last update.

PythonちゃんでDiscordに投稿されたゲーム系URLを別チャンネルにブチこむよ

Last updated at Posted at 2021-04-07

あくまで備忘録なので、自分用メモ的に記載。

discord.pyちゃんはPythonのバージョンに注意が必要。
今回は3.6で作成。

pyenv install 3.6.13
pyenv local 3.6.13

これらをやった上で、pip install python.py実行。

CHANNEL_IDはDiscordにて確認。
※要開発者モードへの切り替え

TOKENはDiscordのディベロッパーページのメニュー部分に
Botとあるのでそこをクリックすると表示されるページのCopyボタンをクリックすると取得できます。
image.png

main.py
import discord

client = discord.Client()

@client.event
async def on_ready():
    #一応確認用
    print("実行中")

@client.event
async def on_message(message):
    #ゲーム系のドメイン名
    l = ["steamcommunity","steampowered","4gamer","gamewith","gamespark","humble","automaton","fanatical"] 

    # Botなら粛清
    if message.author.bot:
        return 

    for item in l :
        #URLでゲーム系だったら別チャンネルに飛ばすよ
        if item in message.content and "http" in message.content  :
            channel = client.get_channel(CHANNEL_ID)
            await channel.send(str(message.content))

client.run(TOKEN)

あとは、同じくDiscordのディベロッパページのOAuth2を選択し、
ScopesのBotにチェックを入れると、URLが表示されます。
このURLを叩いて、設置したいDiscordのサーバを選択してあげるだけ。
image.png

Herokuちゃんとかで動きっぱなしにするといいですよ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0