You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在interactions.py中修改Discord机器人的在线状态?

Issue Setting Discord Bot Presence with interactions.py

I'm working on a Discord bot using the interactions.py library, but I'm stuck trying to set its online presence activity. No matter what I do, the bot's status doesn't update to show the game I want. Here's the code I've been testing:

import interactions
import os

from keep_alive import keep_alive

bot = interactions.Client(token=os.getenv('TOKEN'), command_prefix="!f")


@bot.event
async def on_start():
 activity = interactions.ClientPresence(
   name="zkus /mravenci",
   type=0,
 )
 await bot.change_presence(
   activity=interactions.PresenceActivityType.GAME(activity))

What's Wrong Here?

There are two key issues with your current code:

  • Incorrect class usage: You're using ClientPresence to define the activity, but that's not the right class for this purpose. ClientPresence represents the full presence state (including status like online/idle), not just the activity itself. You should use interactions.Activity instead.
  • Misusing the ActivityType enum: PresenceActivityType.GAME is an enum member, not a function you can call with an argument. You specify the activity type as a parameter when creating the Activity object.

Corrected Code

Here's the fixed version that should properly set your bot's presence:

import interactions
import os

from keep_alive import keep_alive

bot = interactions.Client(token=os.getenv('TOKEN'), command_prefix="!f")


@bot.event
async def on_start():
    # Create the activity object with the correct type and name
    activity = interactions.Activity(
        name="zkus /mravenci",
        type=interactions.PresenceActivityType.GAME
    )
    # Update the bot's presence with the activity
    await bot.change_presence(activity=activity)

Explanation of Changes

  • Swapped ClientPresence for interactions.Activity, which is the correct class to define what the bot is "doing".
  • Set the type parameter directly to PresenceActivityType.GAME instead of trying to wrap the activity with it. This tells Discord that the bot is playing a game.
  • Cleaned up indentation for better readability.

Once you run this corrected code, your bot should show up as "Playing zkus /mravenci" in Discord's user list.

内容的提问来源于stack exchange,提问作者Jakub Šidlík

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 18:10:31