如何解决Discord.py:'Nonetype' 对象没有属性 'change_presence'
已修复,修复 = 等待 ctx.bot.change_presence。
这是我使用@bot.command() 的命令的代码,但不知何故当我使用@commands.command() 时它不起作用
bot = commands.Bot(command_prefix = !)
@commands.command()
async def playgame(ctx,game: str=None):
game_count = False
game_list = []
if game:
game_list.append(game)
game_activity = discord.Activity(name=game,type=discord.ActivityType.playing)
activity = discord.Activity(name=".commands",type=discord.ActivityType.listening)
if game_count:
await ctx.send("I'm already playing " + str(game_list[0]))
else:
game_count = True
await ctx.send("ok!")
await bot.change_presence(activity=game_activity) #This calls the error
await asyncio.sleep(60)
await ctx.send("Gotta go,imma stop playing " + str(game_list[0]) + ",bye")
await bot.change_presence(status=discord.Status.dnd,activity=activity)
game_count = False
game_lib = []
else:
msg = "I can't play nothing,use .playgame <game>"
await ctx.send(msg)
def setup(bot):
bot.add_command(playgame)
解决方法
问题可能只是你没有将命令前缀放在引号中,所以它没有被格式化为字符串并弄乱了整个脚本。
解决方案是:
bot = commands.Bot(command_prefix = "!")
*刚注意到你已经修好了
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。