8
12

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 1 year has passed since last update.

discord.pyでステータス(プレイ中)をする方法

Last updated at Posted at 2021-05-30

こんにちは
今日はdiscord.pyでステータス(プレイ中)にする方法です

動作環境

Python 3.8以上
discord.py 1.5以上

discord.Client版コード

play.py
import discord

client = discord.Client(intents=discord.Intents.all())

@client.event
async def on_ready():
    print("Botは正常に起動しました!")
    print(client.user.name)  # Botの名前
    print(client.user.id)  # ID
    print(discord.__version__)  # discord.pyのバージョン
    print('------')
    await client.change_presence(activity=discord.Game(name="TEST"))

client.run("TOKEN")

commandsフレームワーク版コード

play.py
import discord

from discord.ext import commands
bot = commands.Bot(
    command_prefix="!",
    help_command=None,
    intents=discord.Intents.all())

@bot.event
async def on_ready():
    print("Botは正常に起動しました!")
    print(bot.user.name)  # Botの名前
    print(bot.user.id)  # ID
    print(discord.__version__)  # discord.pyのバージョン
    print('------')
    await bot.change_presence(activity=discord.Game(name="TEST"))

bot.run("TOKEN")

実際に動かす

これでBotを動かしてみましょう
スクリーンショット 2021-05-30 105131.jpg
こうなると成功です
TESTを変えたかったら(name="TEST"))のTESTを変えてください

discord.Client版サーバー数

play.py
import discord

client = discord.Client(intents=discord.Intents.all())

@client.event
async def on_ready():
    print("Botは正常に起動しました!")
    print(client.user.name)  # Botの名前
    print(client.user.id)  # ID
    print(discord.__version__)  # discord.pyのバージョン
    print('------')
    await client.change_presence(activity=discord.Game(name=f"TEST{len(client.guilds)}サーバー"))

client.run("TOKEN")

commandsフレームワーク版サーバー数

play.py
import discord

from discord.ext import commands
bot = commands.Bot(
    command_prefix="!",
    help_command=None,
    intents=discord.Intents.all())

@bot.event
async def on_ready():
    print("Botは正常に起動しました!")
    print(bot.user.name)  # Botの名前
    print(bot.user.id)  # ID
    print(discord.__version__)  # discord.pyのバージョン
    print('------')
    await bot.change_presence(activity=discord.Game(name=f"TEST{len(bot.guilds)}"))

bot.run("TOKEN")

これで導入サーバー数が表示されます

よいDiscordライフを

参考

8
12
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
8
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?