【问题标题】:So Discord bot statuses.....how do I set them?所以不和谐机器人状态.....我该如何设置它们?
【发布时间】:2021-03-19 18:29:49
【问题描述】:

所以我想要我的不和谐机器人的状态,一个“正在玩”的状态,但不是真正的游戏,我知道你可以做到。在 python 中编写不和谐机器人时,我该怎么做?

编辑:我有这段代码,但它不起作用。

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio


client = discord.Client()


PREFIX = ("$")
bot = commands.Bot(command_prefix=PREFIX)

@bot.event
async def on_ready():
    await bot.change_presence(activity=discord.Game(name="testing this code"))
    print("Bot is ready!")



client.run(bot_token)

【问题讨论】:

    标签: discord discord.py bots


    【解决方案1】:

    要更改机器人的活动,您需要使用 Client.change_presence 使用其activity kwarg,通过以下任何一项:

    • discord.Game
    • discord.Streaming(需要有效的 twitch URL,而不是首页)
    • discord.Activity 具有有效的 ActivityTypename

    【讨论】:

      【解决方案2】:

      你需要设置一个状态如change_presence所示

      @bot.event
      async def on_ready():
          await bot.change_presence(status=discord.Status.online, activity=discord.Game("Testing this code"))
          print("Bot is ready!")
      

      【讨论】:

        【解决方案3】:
        # Setting Playing status
        await bot.change_presence(activity=discord.Game(name="a game"))
        
        # Setting Streaming status
        await bot.change_presence(activity=discord.Streaming(name="My Stream", url=my_twitch_url))
        
        # Setting Listening status
        await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"))
        
        # Setting Watching status
        await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="a movie"))
        

        (感谢来自 this 的 NOT kar1m yt 我从谁那里复制了这篇文章 :))

        【讨论】:

          猜你喜欢
          • 2021-05-27
          • 2021-05-07
          • 1970-01-01
          • 2021-11-10
          • 2020-03-19
          • 2022-10-24
          • 1970-01-01
          • 1970-01-01
          • 2021-03-31
          相关资源
          最近更新 更多