简体   繁体   English

如何制作自定义状态discord.py

[英]How make custom status discord.py

Why is my code not working?为什么我的代码不起作用?

@bot.event
async def on_ready():
    print('Bot is now working!')
    await bot.change_presence(activity=discord.CustomActivity(name='Custom status' ,emoji='🖥️'))

And gives me an error.并给我一个错误。

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'

How fix is error?错误是如何修复的?

I'm late to the party, WayToDoor is right, bots can't use custom status, I found that they "can use it" but it's invisible except bots can see it's a custom status and you will see "custom status" on the bot profile.我迟到了,WayToDoor 是对的,bots 不能使用自定义状态,我发现他们“可以使用它”但它是不可见的,除了 bots 可以看到它是一个自定义状态,你会在机器人简介。

There is Playing, Watching, Listening to, and Streaming available for the bots no problem有播放、观看、收听和流式传输可供机器人使用,没问题

You also now have an option to use "Competing in" too, which has type 5. I can't see it on the docs yet so I'm assuming it's not implemented yet.您现在还可以选择使用“Competing in”,它的类型为 5。我还没有在文档中看到它,所以我假设它还没有实现。

#this is how "Competing in" is set.
discord.Activity(name="Test", type=5)

this should work.这应该有效。

Bots cannot use custom statuses yet.机器人还不能使用自定义状态。 Use Playing or Watching instead.改用PlayingWatching See https://github.com/Rapptz/discord.py/issues/2400https://github.com/Rapptz/discord.py/issues/2400

to make a custom activity you should use:要进行自定义活动,您应该使用:

activityvar = discord.Activity(type=discord.ActivityType.custom,state="NAMEOFMYACTIVITY")
await bot.change_presence(activity=activityvar)

for some reason the custom activity uses the state argument instead of name to define the name出于某种原因,自定义活动使用状态参数而不是名称来定义名称

try these:试试这些:

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

Try this:试试这个:

@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM