0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

discordBOTで大きいサイズのスタンプ機能を実装する

Posted at

はじめに

本来discordに備え付けの「emoji」機能を利用して、あらかじめ自分で用意した画像をやりとりできるが、
emoji機能では画像が小さくなりすぎてしまうという問題があるため、それを解決しようと考えた。

解決策

特定のキーワードに反応して画像を送信するBOTを作成し、大きいサイズの画像をユーザー間で簡単に共有できるようにする。

環境

Python 3.6.8
discord.py 1.2.5

実際のコード

import discord

TOKEN = 'hoge'  # 自身のBOTに割り当てられたトークンを入力

# 起動時の処理
@client.event
async def on_ready():
    print('We have logged in as %s' % client)

# メッセージを受信したとき、スタンプを送信する処理
@client.event
async def on_message(message):

    if message.author == client.user:
        return

    if message.content == '/img':  # 画像出力のトリガーにしたいキーワード
        await message.channel.send(file=discord.File('img.png'))  # 出力する画像のパス

client.run(TOKEN)

複数のスタンプを用意したい場合は、


if message.content == '/img':
    await message.channel.send(file=discord.File('img.png'))

を繰り返す。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?