所以我有这个代码作为我的前缀。我没有问题。它工作正常,但是每当我向我的机器人发送消息时,都会出现此错误。反正有没有忽略或解决它?谢谢
with open("prefix.json") as f:
prefixes = json.load(f)
default_prefix = "?"
def prefix(client, message):
id = message.guild.id
return prefixes.get(id, default_prefix)
client = commands.Bot(command_prefix=prefix)
@client.command(name="Prefix", aliases=["prefix", "setprefix"])
@commands.has_permissions(manage_guild=True)
async def _prefix(ctx, new_prefix):
msg = ctx.message
prefixes[msg.guild.id] = new_prefix
with open("prefix.json", "w") as f:
json.dump(prefixes, f, indent=4)
Error:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 930, in on_message
await self.process_commands(message)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 926, in process_commands
ctx = await self.get_context(message)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 842, in get_context
prefix = await self.get_prefix(message)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 787, in get_prefix
ret = await discord.utils.maybe_coroutine(prefix, self, message)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\utils.py", line 317, in maybe_coroutine
value = f(*args, **kwargs)
File "C:/Users/user/Desktop/test.py", line 14, in prefix
id = message.guild.id
AttributeError: 'NoneType' object has no attribute 'id'
答案 0 :(得分:0)
product
将是original_price
(因为它们没有被发送给公会)。您应该在function sortAscendingPrice(a, b) {
return a.original_price - b.original_price;
}
function sortDescendingPrice(a, b) {
return b.original_price - a.original_price;
}
function sortAscendingProduct(a, b) {
return a.product - b.product;
}
function sortDescendingProduct(a, b) {
return b.product - a.product;
}
const data = [
{
product: 1,
price: [
{id: 1, original_price: 18},
{id: 2, original_price: 10}
]
},
{
product: 2,
price: [
{id: 1, original_price: 12},
{id: 2, original_price: 15},
{id:3, original_price: 5}
]
}
];
const sortedData = data
.map(el => {
return {
product: el.product,
price: el.price.sort(sortAscendingPrice)
};
})
.sort(sortDescendingProduct);
函数中为此添加一个大小写。
message.guild