[英]How make custom status discord.py
為什么我的代碼不起作用?
@bot.event
async def on_ready():
print('Bot is now working!')
await bot.change_presence(activity=discord.CustomActivity(name='Custom status' ,emoji='🖥️'))
並給我一個錯誤。
Ignoring exception in on_ready
Traceback (most recent call last):
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/discord/client.py", line 270, in _run_event
await coro(*args, **kwargs)
File "main.py", line 30, in on_ready
await bot.change_presence(activity=discord.CustomActivity(name='Custom status' ,emoji='🖥️'))
AttributeError: module 'discord' has no attribute 'CustomActivity'
錯誤是如何修復的?
我遲到了,WayToDoor 是對的,bots 不能使用自定義狀態,我發現他們“可以使用它”但它是不可見的,除了 bots 可以看到它是一個自定義狀態,你會在機器人簡介。
有播放、觀看、收聽和流式傳輸可供機器人使用,沒問題
您現在還可以選擇使用“Competing in”,它的類型為 5。我還沒有在文檔中看到它,所以我假設它還沒有實現。
#this is how "Competing in" is set.
discord.Activity(name="Test", type=5)
這應該有效。
機器人還不能使用自定義狀態。 改用Playing
或Watching
。 見https://github.com/Rapptz/discord.py/issues/2400
要進行自定義活動,您應該使用:
activityvar = discord.Activity(type=discord.ActivityType.custom,state="NAMEOFMYACTIVITY")
await bot.change_presence(activity=activityvar)
出於某種原因,自定義活動使用狀態參數而不是名稱來定義名稱
試試這些:
# 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"))
試試這個:
@bot.command(pass_context=True)
async def Self_Clock(ctx):
print("[+]: Status Changer Loaded")
await ctx.message.delete()
from datetime import datetime
headers = {
'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7',
'Content-Type': 'application/json',
'Authorization': token,
}
request = requests.Session()
while True:
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
setting = {
'status': "online",
"custom_status": {"text": f"[+]: My current time: {current_time}"}
}
request.patch("https://canary.discordapp.com/api/v6/users/@me/settings",headers=headers, json=setting, timeout=10)
time.sleep(1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.