我的discord.py Python库有问题。每当有人对邮件做出反应时,我都会出错。
Python不会显示错误的来源,但是我认为discord.py中存在错误。 上周,该代码有效,但现在不再有效。我对此感到头疼。有人可以帮我吗?
这是我的代码:
import discord
from emojis import emojis
import msg
from discord.utils import get
from discord.ext import commands
import json
from uuid import uuid4
shop_channels = []
orders = {}
cmd_prefix = "dsb!"
def check_perms(user):
for role in user.roles:
if role.name == "?????":
return True
return False
def check_command(message, command):
if message.startswith(cmd_prefix + command):
return True
else:
return False
def save_settings():
settings = {}
settings["shop_channels"] = shop_channels
settings["orders"] = orders
with open("data.json", "w") as file:
json.dump(settings, file)
def load_settings():
global shop_channels
global orders
with open("data.json") as file:
settings = json.load(file)
orders = settings["orders"]
shop_channels = settings["shop_channels"]
print(shop_channels)
class MyClient(discord.Client):
async def on_ready(self):
self.msg = msg.Msg(True, "DiShoBo")
print('-------')
print('Logged in as')
print('Username:', self.user.name)
print('ID:', self.user.id)
print('------', end="\n\n")
load_settings()
print("Settings loaded!\n\n")
async def on_reaction_add(self, reaction, user):
print("hello")
if shop_channels is None or reaction.message.channel.id not in shop_channels:
return
try:
if reaction.emoji == emojis["shopping_cart"]:
order_id = uuid4()
item = reaction.message.content.partition('\n')[0]
amount = reaction.message.content.partition('\n')[2]
self.msg.debug("Got new order from user {0} for Item: {1}! OrderID: {2}".format(
user, item, order_id))
if user.dm_channel == None:
await user.create_dm()
message = await user.dm_channel.send("You ({2}) added the Item: '{0}' for {1} to your shopping cart!\nClick on :white_check_mark: to finish your order then go back to Angels 2B2T shop, or if you want to keep shopping, just go back to the shop and add more items.\nIf you want to clear your shopping cart, click the {3} below.\n\nYour OrderID is: {4}".format(item, amount, user.mention, emojis["cross_mark"], order_id))
# await message.add_reaction(emojis["check_mark_box"])
# await message.add_reaction(emojis["cross_mark"])
if not message.author in orders:
orders.update(
{message.author: {"user": message.author, "ID": order_id, "items": []}})
print(orders[message.author]["items"])
orders[message.author]["items"].append({item, amount})
print(orders[message.author]["items"])
if not reaction.me and reaction.count > 1:
await reaction.remove(user)
else:
await reaction.remove(user)
except:
pass
# * CONNECT
client = MyClient()
client.run('TOKEN')
答案 0 :(得分:0)
这是discord.py
库中的错误,但已在更新1.3.2
中修复。