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

如何在Discord.js v14(JavaScript)中设置机器人活动状态

为Discord机器人设置活动状态

使用discord.js(Node.js)

  • 设置「正在玩游戏」状态:
    const { Client, ActivityType } = require('discord.js');
    const client = new Client({ intents: [/* 填入你的必要权限,如Guilds等 */] });
    
    client.on('ready', () => {
      client.user.setActivity('你的游戏名称', { type: ActivityType.Playing });
      console.log(`已登录:${client.user.tag}`);
    });
    
    client.login('你的机器人令牌');
    
  • 设置「正在观看YouTube」状态:
    client.user.setActivity('youtube.com', { type: ActivityType.Watching });
    

使用discord.py(Python)

  • 设置「正在玩游戏」状态:
    import discord
    from discord.ext import commands
    
    intents = discord.Intents.default()
    bot = commands.Bot(command_prefix='!', intents=intents)
    
    @bot.event
    async def on_ready():
        await bot.change_presence(activity=discord.Game(name='你的游戏名称'))
        print(f'已登录:{bot.user}')
    
    bot.run('你的机器人令牌')
    
  • 设置「正在观看YouTube」状态:
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='youtube.com'))
    

注意事项

  • 必须在Discord开发者门户的机器人设置中开启Presence Intent权限,否则无法修改状态。
  • 支持的活动类型还包括Listening(收听)、Streaming(直播)等,不同库的枚举值命名略有区别,可参考对应库的官方文档。

内容的提问来源于stack exchange,提问作者LukeHjo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 13:01:16