https://github.com/legacyks/KsBot
我将#registration和#registration info部分添加到我的代码后,播放我音乐的部分停止工作。当我删除#registration和#registration info部分时,我的音乐效果非常好。我不知道music.py是做什么的,我从youtube上的视频中得到了这个
相关的代码块:
#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))
对于python和discord.py来说还是比较新的,请发送帮助:(
注意:Dun担心令牌和客户端的秘密,我已经改变了
答案 0 :(得分:1)
万一有人有类似的问题,我将在这里重写答案
回答:问题在于您使用commands
方式和on_message
创建命令的方式。要解决此问题,您可以使用on_message
命令替换commands
命令,也可以在await bot.process_commands(message)
on_message