Squ*_*quv 9 python bots discord discord.py
对我来说可能很难,但我相信 stackoverflow 的力量,
我想将机器人状态从播放更改为观看。我试试这个,但它仍然在播放状态。
代码:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
PREFIX = ("$")
bot = commands.Bot(command_prefix=PREFIX, description='Hi')
@bot.event
async def on_ready():
activity = discord.Game(name="Netflix", type=3)
await bot.change_presence(status=discord.Status.idle, activity=activity)
print("Bot is ready!")
bot.run('TOKEN')
Run Code Online (Sandbox Code Playgroud)
Squ*_*quv 62
# 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"))
Run Code Online (Sandbox Code Playgroud)
小智 8
提醒大家,不要在你的机器人或客户端的 on_ready 中更改_presence(或进行 API 调用)。Discord 很有可能在 READY 或 GUILD_CREATE 事件(1006 或 1000 关闭代码)期间完全断开您的连接,并且您无能为力。
相反,在这些类的构造函数中设置activity和statuskwargs。
播放-> 活动 = discord.Game(name="!help")
流媒体-> 活动 = discord.Streaming(name="!help", url="twitch_url_here")
听力-> 活动 = discord.Activity(type=discord.ActivityType.listening, name="!help")
观看-> 活动 = discord.Activity(type=discord.ActivityType.watching, name="!help")
bot = commands.Bot(command_prefix="!", activity=activity, status=discord.Status.idle)
Run Code Online (Sandbox Code Playgroud)
基本上:不要在 on_ready 中做事。