Python 不一致的bot无法识别命令
我是discord API的新手,我很难弄清楚为什么我的命令不能被识别。我已经通读了文档,但我不确定该去哪里看。任何帮助都将不胜感激。不要介意硬编码的列表。我计划将来改变这一点。现在我只想确保它能正常工作Python 不一致的bot无法识别命令,python,bots,discord,Python,Bots,Discord,我是discord API的新手,我很难弄清楚为什么我的命令不能被识别。我已经通读了文档,但我不确定该去哪里看。任何帮助都将不胜感激。不要介意硬编码的列表。我计划将来改变这一点。现在我只想确保它能正常工作 import discord from discord.ext.commands import Bot from discord.ext import commands import asyncio Client = discord.Client() client = commands.Bo
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
Client = discord.Client()
client = commands.Bot(command_prefix = "!")
@client.event
async def on_ready():
print("Bot online!")
@client.command(pass_context=True)
async def add_roles(member, *roles):
if message.content.startswith("!role"):
role_list = ["CS101", "CS492", "CS360", "CS213", "CS228", "CS401", "CS440", "CS450", "CS480", "CS410", "CS420", "CS430", "CS108", "CS111", "CS226", "CS312", "CS405", "CS413", "CS435", "CS499", "CS250", "CS475", "CS445"]
entered_role = message.content[6:].upper()
role = discord.utils.get(message.server.roles, name=entered_role)
if role is None or role.name not in role_list:
# If the role wasn't found by discord.utils.get() or is a role that we don't want to add:
await client.send_message(message.channel, "Role doesn't exist.")
return
elif role in message.author.roles:
# If they already have the role
await client.send_message(message.channel, "You already have this role.")
else:
try:
await client.add_roles(message.author, role)
await client.send_message(message.channel, "Successfully added role {0}".format(role.name))
except discord.Forbidden:
await client.send_message(message.channel, "I don't have perms to add roles.")
@client.command(pass_context=True)
async def remove_roles(member, *roles):
if message.content.startswith("!unassign"):
role_list = ["CS101", "CS492", "CS360", "CS213", "CS228", "CS401", "CS440", "CS450", "CS480", "CS410", "CS420", "CS430", "CS108", "CS111", "CS226", "CS312", "CS405", "CS413", "CS435", "CS499", "CS250", "CS475", "CS445"]
roles_cleared = True
for r in role_list:
# Check every role
role = discord.utils.get(message.server.roles, name=r)
if role in message.author.roles:
# If they have the role, get rid of it
try:
await client.remove_roles(message.author, role)
except discord.Forbbiden:
await client.send_message(message.channel, "I don't have perms to remove roles.")
roles_cleared = False
break
if roles_cleared:
await client.send_message(message.channel, "Roles successfully cleared.")
client.run("mytoken")
在函数中,您需要有ctx变量
@client.comman(pass_context = True)
async def some_command(ctx, bla_bla, and_bla_bla):
pass
我想。。。
告诉我这是否对u有帮助你的函数名就是命令名我觉得自己像个白痴。谢谢