AttributeError: 'BotClient' Object Has No Attribute 'loop' With Declaring An Instance
Trying to write a Discord Bot in Python, although having trouble. Currently receiving the error 'AttributeError: 'BotClient' object has no attribute 'loop''. I've looked this up be
Solution 1:
You are modifying the __init__()
function that extends to the class discord.Client
. Apparently, you need to initialize the __init()__
inside the class discord.Client
because your new init function overwrote the discord's init function (aka the super class init function). And this should be fairly simple to fix. Just initialize it inside your new init function:
class BotClient(discord.Client):
def __init__(self, prefix, current_game, *args, **kwargs):
self.pfx = prefix
self.curr_game = current_game
super().__init__(*args, **kwargs)
async def on_ready(self):
print(f'{self.user} has connected to Discord!')
await self.change_presence(status=discord.Status.idle, activity=self.curr_game)
#@self.event
async def on_message(self, message):
if message.author == self.user:
return
if message.content.startswith('%s hello' % self.pfx):
await message.channel.send('very naisu caesar-chan')
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
CHANNEL = os.getenv('CHANNEL_TOKEN')
CUR_GAME = os.getenv('GAME_ENV')
RockBot = BotClient(".rb", CUR_GAME)
RockBot.run(TOKEN)
Post a Comment for "AttributeError: 'BotClient' Object Has No Attribute 'loop' With Declaring An Instance"