小编ktz*_*tzr的帖子

如何检查用户是否在不和谐中具有特定角色

这应该检查特定的人是否有或没有静音角色

    @bot.command(pass_context=True)
    @commands.has_role("Admin")
    async def unmute(ctx, user: discord.Member):
        role = discord.utils.find(lambda r: r.name == 'Member', 
    ctx.message.server.roles)
        if user.has_role(role):
            await bot.say("{} is not muted".format(user))
        else:
            await bot.add_roles(user, role)
Run Code Online (Sandbox Code Playgroud)

抛出这个错误

命令引发异常:AttributeError: 'Member' object has no attribute 'has_role'

我不知道该怎么做所以我真的很感激我能得到的每一个帮助

python python-3.x discord.py

7
推荐指数
1
解决办法
3万
查看次数

从 Python 2 加载 Python 3 pickle

我有一个在 python 2 中创建的泡菜文件(我不知道具体是如何创建的)。它打算由以下 python 2 行加载,在 python 3 中使用时(不出所料)不起作用:

with open('filename','r') as f:
    foo, bar = pickle.load(f)
Run Code Online (Sandbox Code Playgroud)

结果:

“ascii”编解码器无法解码位置 1219 中的字节 0xc2:序号不在范围内 (128)

手动检查文件表明它是 utf-8 编码的,因此:

with open('filename','r', encoding='utf-8') as f:
    foo, bar = pickle.load(f)
Run Code Online (Sandbox Code Playgroud)

结果:

类型错误:需要类似字节的对象,而不是“str”

使用二进制编码:

with open('filename','rb', encoding='utf-8') as f:
    foo, bar = pickle.load(f)
Run Code Online (Sandbox Code Playgroud)

结果:

ValueError:二进制模式不采用编码参数

没有二进制编码:

with open('filename','rb') as f:
    foo, bar = pickle.load(f)
Run Code Online (Sandbox Code Playgroud)

结果:

UnpicklingError: 无效的加载键,“ ”。

这个泡菜文件是不是刚刚坏了?如果没有,我怎样才能在 python 3 中撬开这个东西?(我已经浏览了大量相关问题,但还没有找到任何有用的东西。)

最后,请注意原始

导入 cPickle 作为泡菜

已被替换为

导入 _pickle 作为泡菜

pickle python-2.7 python-3.x

5
推荐指数
1
解决办法
6898
查看次数

对于HelloWorld类型,方法JFrame未定义

我不知道为什么但是我的hello world java项目出错:

对于HelloWorld类型,方法JFrame是未定义的.

我刚刚开始,有人可以向我解释错误和解决方案吗?

package helloworld;

import javax.swing.JFrame;

public class HelloWorld {
    public static HelloWorld HelloWorld;
    public final int WIDTH = 800, HEIGHT = 800;

    public HelloWorld() {
        JFrame jframe = JFrame();
        jframe.setSize(WIDTH, HEIGHT);
        jframe.setVisible(true);

    }

    public static void main(String[] args) {
        HelloWorld = new HelloWorld();
    }
}
Run Code Online (Sandbox Code Playgroud)

java methods swing undefined

0
推荐指数
1
解决办法
89
查看次数

标签 统计

python-3.x ×2

discord.py ×1

java ×1

methods ×1

pickle ×1

python ×1

python-2.7 ×1

swing ×1

undefined ×1