-4

https://github.com/legacyks/KsBot

After i add the #registration and #registration info section to my code, the part which play my music stops working. when i remove #registration and #registration info section, my music works perfectly fine. I have no idea what the music.py does, i got that from a video on youtube

Relevant Chunks of Code:

#Bot Initiations
KsBot = Bot(command_prefix ='//')
startup_extensions = ["Music"]

#Display Bot Info and Discord Version
@KsBot.event
async def on_ready():
    print('Discord Version : ' + discord.__version__)
    print('Bot User Name : ' + KsBot.user.name)
    print('Bot ID : ' + KsBot.user.id)
    print('----------------------')
    print("Number of registered user in this server: " + str(numberOfMembers))

#Registration Info
registeredMembersFile = open("RegisteredMembers.txt")
registeredMembers = registeredMembersFile.read()
registeredMembers = ast.literal_eval(registeredMembers)
numberOfMembers = len(registeredMembers)
registeredMembersFile.close()

#Registration
@KsBot.event
async def on_message(message):
    if message.content.startswith("//register"):
        sender = message.author.id
        print("Registering ID " + sender + " ...")
        if sender in registeredMembers:
            await KsBot.send_message(message.author,"Registration Fail:Already a memmber")
            print("Registration Failed: Already a member")
        elif sender not in registeredMembers:
            print("User " + sender + " is not registered")
            registeredMembers[sender] = 1000
            registeredMembersFile = open("RegisteredMembers.txt",'w')
            registeredMembersFile.write(pprint.pformat(registeredMembers))
            registeredMembersFile.close()
            await KsBot.send_message(message.author,"Registration OK!")
            print("Registeration Successful")

#YetiGuy Music Bot
class Main_Commands():
        def __init__(self,bot):
            self.bot = bot

if __name__ == "__main__":
    for extension in startup_extensions:
        try:
            KsBot.load_extension(extension)
        except Exception as e:
            exc = '{}: {}'.format(type(e).__name__,e)
            print("Failed to load extension {}\n{}".format(extension,exc))

still relatively new to python and discord.py , please send help :(

Note: Dun worry about the token and client secret, i've already changed that

Joshua
  • 40,822
  • 8
  • 72
  • 132
LegacyKS
  • 15
  • 3
  • 8
  • Maybe you’re using the same variables as in music.py, try checking that – DevOps Apr 26 '18 at 19:01
  • @DevOps yep i've checked, doesnt seem to have any same variables – LegacyKS Apr 26 '18 at 19:10
  • Where exactly are you adding registration and registrationinfo? – DevOps Apr 26 '18 at 23:17
  • @DevOps line 29 of KsBot.py – LegacyKS Apr 27 '18 at 17:20
  • Please edit your question and add the lines of code you want to add, this way we can see what is going on. – DevOps Apr 28 '18 at 08:58
  • @DevOps Sorry for not adding the code in the question, i thought it was rather long so i posted a github link instead, i've cut out the relevant chunk of codes. The #registration and #registration info are codes that i wanted to add and seem to be the cause of the problem, the bot works perfectly fine when i remove those codes – LegacyKS Apr 28 '18 at 19:27
  • 1
    @LegacyKS the problem is that you use both the `commands` way, and `on_message` way of creating commands. To fix this, you can either replace your `on_message` commands with `commands` commands, or add `await bot.process_commands(message)` after your command `if` statement in `on_message`(PS sorry for answering in a comment, I am unable to put it in an actual answer because your question was marked as off-topic) – qspitzer Apr 28 '18 at 21:50
  • Yes! Exactly what @qspitzer said! – DevOps Apr 29 '18 at 00:59
  • @qspitzer and DevOps Ahhhh thank you so much guys – LegacyKS Apr 29 '18 at 20:39

1 Answers1

2

Just in case someone has a similar question, I am going to rewrite the answer in here

Answer: The problem is that you use both the commands way, and on_message way of creating commands. To fix this, you can either replace your on_message commands with commands commands, or add await bot.process_commands(message) after your command if statement in on_message

qspitzer
  • 729
  • 1
  • 5
  • 14