【发布时间】:2021-04-24 04:34:04
【问题描述】:
我正在尝试编写 Discord 机器人,并且我想添加命令,以便具有踢/禁止权限的人可以使用踢/禁止命令。我添加了许多不同形式的踢和禁止命令,但它们都不能正常工作。我绝对肯定踢/禁止命令是正确的。我开始觉得我的其余代码有问题,导致踢/禁止命令不起作用。
这是我目前拥有的:
from discord.ext import commands
import os
from dotenv import load_dotenv
import logging
# Enables logging
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
# Assigns the Discord client to a variable called client
client = commands.Bot(command_prefix='$')
# Loads .env
load_dotenv()
# Prints a message stating that the bot is loggen in
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
# Prints the help message when a user says $help
@client.event
async def on_message(message):
if message.content.startswith('$help'):
await message.channel.send('''**Hydra Help**
*This message contains a list of commands and what they do.*
__help__: Prints this message.''')
# Starts the bot
client.run(os.getenv('TOKEN'))
到目前为止,我的代码是否有任何问题可能导致踢/禁止命令不起作用?
【问题讨论】:
-
这能回答你的问题吗? How to kick users on command
标签: python discord bots discord.py