如何更改discord.py机器人状态

时间:2019-12-01 13:49:23

标签: 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')

7 个答案:

答案 0 :(得分:3)

提醒所有人,请勿在您的机器人或客户端中的 on_ready 中更改_presence(或进行 API 调用)。 Discord 很有可能在 READY 或 GUILD_CREATE 事件(1006 或 1000 关闭代码)期间完全断开您的连接,并且您无能为力。

相反,在这些类的构造函数中设置 activitystatus kwargs。

播放 -> 活动 = 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)

基本上:不要在 on_ready 中做事。

答案 1 :(得分:2)

您可以使用此Ezz!

# 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"))

答案 2 :(得分:0)

根据this issue,Client.change_presence中的游戏关键字参数已重命名为activity,因此您的代码应类似于

activity = discord.Game(name="Just")
await client.change_presence(status=discord.Status.idle, activity=activity)

答案 3 :(得分:0)

尽管自定义状态

,该漫游器仍可以是Playing XStreaming Y

https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Bot.change_presence

答案 4 :(得分:0)

history.push(localhost:3000/invite/leadueid-1

答案 5 :(得分:0)

只需使用:

@client.event
async def on_ready():
    await client.change_presence(activity=discord.Streaming(name='Fortnite', url='https://www.twitch.tv/UR_TWITCH_GOES_HERE You cant do YT only Twitch.'))
    print("Bot is connected to all of the available servers in the bots mainframe.")

对于流媒体,但对于其他人,我无能为力。

答案 6 :(得分:0)

如果你想要正常的存在,那么这样做:


await bot.change_presence(activity=discord.Streaming(name="My Stream", url=my_twitch_url))

await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"))

await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="a movie"))```

#but if you want to make the bot change status every 5 minutes try this :

async def ch_pr():
 await client.wait_until_ready()

 statuses = ["Vodka Or beer? || bb:help",f"listening on {len(client.guilds)} server's","Still need help? do bb:guide for more help!"]

 while not client.is_closed():

   status = random.choice(statuses)

   await client.change_presence(activity=discord.Game(name=status))

   await asyncio.sleep(5)

client.loop.create_task(ch_pr())