【发布时间】:2021-09-01 21:58:53
【问题描述】:
我在 discord.py 上写了一个简单的函数
我曾尝试使用在线数据库来托管机器人
import discord
from discord.ext import commands
from replit import db
client = discord.Client()
bot = commands.Bot(">", case_insensitive = True)
db['Plaksha'] = {'Server_Specific_Stuff':{'Channel for commands':0}}
chan_for_commands = 1
@bot.command()
async def set_commands_channel(ctx):
global chan_for_commands
print(chan_for_commands)
temp = ctx.message.channel
db['Plaksha']['Server_Specific_Stuff']['Channel for commands'] = temp
chan_for_commands = temp
print(chan_for_commands)
pass
token = ""
bot.run(token)
这个函数应该更新变量 chan_for 命令。 我尝试过 Replit.com 以外的其他客户端,但它不起作用!
有没有办法避免这个错误?如果是这样,是否有另一种方法可以在本地和在线数据库(数据库)中更新 chan_for_commands?
错误提示:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: Circular reference detected
【问题讨论】:
-
你确定
ctx.message.channel只是一个标识符,而不是例如一个东西?也许你需要ctx.message.channel.id或类似的?
标签: python json circular-reference repl.it