简体   繁体   English

discord.py:有什么可以使它在踢/禁止命令不起作用的地方吗?

[英]discord.py: Is there anything that could be making it where kick/ban commands don't work?

I am trying to code a Discord bot and I would like to add commands so that people with kick/ban permissions can use the kick/ban commands.我正在尝试编写 Discord 机器人,我想添加命令,以便具有踢/禁止权限的人可以使用踢/禁止命令。 I have added many different forms of kick and ban commands, but none of them function correctly.我添加了许多不同的 forms 踢和禁止命令,但没有一个是正确的 function。 I am absolutely positive the kick/ban commands were correct.我绝对肯定踢/禁止命令是正确的。 I am starting to get the feeling that there is something is wrong with the rest of my code, making it where kick/ban commands don't function.我开始觉得我的代码的 rest 有问题,导致踢/禁止命令不是 function。

Here is what I currently have:这是我目前拥有的:

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'))

Is there anything wrong with my code so far that may be causing kick/ban commands to not work?到目前为止,我的代码是否有任何问题可能导致踢/禁止命令不起作用?

You have to just do this:你必须这样做:

Kick:踢:

await ???(For example member or ctx.author).kick(reason=???)

Ban:禁止:

await ???(For example member or ctx.author).ban(reason=???)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM