0

I was writing a simple function on discord.py

I had tried online databases to host the bot

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)

This function is supposed to update the variable chan_for commands. I had tried other clients other than Replit.com and it does not work!

Is there a way to escape this error? If so is there another way to update chan_for_commands both locally and in the online db (data base)?

The error says:

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
Vishal
  • 11
  • 2
  • Are you sure `ctx.message.channel` is just an identifier and not e.g. an object? Maybe you'd need `ctx.message.channel.id` or similar? – AKX Jun 17 '21 at 06:51

1 Answers1

0

I've run into this error before and the solution is by changing the variable into a string. The database won't take in values that aren't specified.

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'] = str(temp)
  
  chan_for_commands = temp

  print(chan_for_commands)
  pass


token = ""

bot.run(token)
wovano
  • 4,543
  • 5
  • 22
  • 49