Joe*_*den 1 bots discord discord.py
我一直在尝试为我自己的服务器编写一个 Discord 机器人。然而,似乎每当我向代码中添加更多命令时,禁止和踢函数就不再正常工作。我多次尝试重写代码,但没有成功。我尝试过重新排列代码,但效果并不好。
client = commands.Bot(command_prefix = '!')
@client.command()
async def kick(ctx, member : discord.Member, *, reason = None):
await member.kick(reason = reason)
@client.command()
async def ban(ctx, member : discord.Member, *, reason = None):
await member.ban(reason = reason)
curseWord = ['die', 'kys', 'are you dumb', 'stfu', 'fuck you', 'nobody cares', 'do i care', 'bro shut up']
def get_quote():
response = requests.get("https://zenquotes.io/api/random")
json_data = json.loads(response.text)
quote = json_data[0]['q'] + " -" + json_data[0]['a']
return(quote)
#ready
@client.event
async def on_ready():
print('LOGGED IN as mr MF {0.user}'.format(client))
@client.event
#detect self messages
async def on_message(message):
if message.author == client.user:
return
#greeting
if message.content.startswith('hello'):
await message.channel.send('ay whatup ma gamer')
#help
if message.content.startswith('!therapy'):
quote = get_quote()
await message.channel.send(quote)
#toxicity begone
msg_content = message.content.lower()
if any(word in msg_content for word in curseWord):
await message.delete()
#environment token
token = os.environ['token']
client.run(token)
Run Code Online (Sandbox Code Playgroud)
您已覆盖该on_message事件,该事件默认处理命令(那些用@client.command()装饰器标记的命令)。当您覆盖它时,您需要明确告诉库处理命令。如Discord.py 文档中所述,您应该在事件末尾添加此行on_message:
await client.process_commands(message)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
103 次 |
| 最近记录: |