python - Discord.py 机器人状态未显示
问题描述
因此,当我尝试向我的 discord python 机器人添加状态时,它不会显示在 discord 上,运行代码时不会出现错误,只是状态不会显示自己。
#Connection to discord
@client.event
async def on_ready():
print({client.user}, 'has connected to Discord!')
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='~help'))
如果有人知道解决此问题的方法,请提供帮助。
解决方案
import discord
import os
import config
import sys
client = discord.Client()
@client.event
async def on_ready():
print({client.user}, 'has connected to Discord!')
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='~help'))
client.run(config.token) #imports token from the config.py
我在我的测试机器人中尝试了你的代码,它工作得很好。我附上了下面的截图和上面的代码。不知道为什么它不适合你。[这是我的全部代码,中间或末尾没有任何附加内容]。
注意:导入配置有我的令牌(所以它不是必要的导入)
推荐阅读
- python - 多元线性回归 100% 准确度
- css - Bootstrap 3.3.1 正在影响整个页面的字体
- python - 查询 SQLite3 时 Python 中的字符串格式
- .net - 当我尝试将客户端 .net 应用程序与 OPC 服务器连接时,来自 HRESULT 的异常:0x80080005 (CO_E_SERVER_EXEC_FAILURE))
- java - 没有成功链接这两个 ffmpeg 命令
- java - 如何等待 Android Firestore 中的嵌套任务?
- ios - 为什么视频没有播放,只在 swift 中显示加载程序
- mysql - laravel 对不同表中的数据进行分组,性能更好
- pattern-matching - 字符串选项 ref 上的 OCaml 匹配
- python - 有没有办法覆盖 tif 文件的“ImageDescription”?