我目前正在尝试使用Discord.py编程Discord机器人。如果我注释掉程序中的“自动调节”部分,Bot就会工作。但是,当我在程序中使用“自动调节”时,bot只运行自动调节而不运行其他任何功能。有谁能帮我找到一种方法来确保程序中的所有内容都正常工作吗
这是我的密码:
#-----------------------------------Setup----------------------------------
import os
import keep_alive
import discord
from discord.ext import commands, tasks
import random
import asyncio
import time
from itertools import cycle
import aiofiles
bot = commands.Bot(command_prefix='?')
bot.remove_command("help")
bot.warnings = {}
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
await bot.change_presence(status = discord.Status.online, activity=discord.Game("Some Trashy Games! "))
#slowmode command
@bot.command()
@commands.has_permissions(manage_messages=True)
async def slowmode(ctx, seconds: int):
await ctx.channel.edit(slowmode_delay=seconds)
slowmode_embed = discord.Embed(title="Slowmode", description="A slowmode was set for this channel", colour=discord.Colour.green())
await ctx.send(embed=slowmode_embed, delete_after=5.0)
#----------------------------------Auto Moderation-------------------------------------
#bad words
bad_words = ["fuck","nigga","fuk","cunt","nut","bitch","dick","d1ck","pussy","asshole","b1tch","b!tch","blowjob","cock","c0ck", "ass","nigger","motherfucker", "f u", "shit", "sht", "whore", "faggot", "fag"]
@bot.event
async def on_message(msg):
for bad_word in bad_words:
if bad_word in msg.content.lower().split(" "):
await msg.delete()
bad_word_embed = discord.Embed(title = "Bad Word", description=f"{msg.author.mention}, please do not say any bad words", color = discord.Color.green())
await msg.channel.send(embed=bad_word_embed, delete_after=5.0)
#--------------------------Errors----------------------------------------
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
embed1 = discord.Embed(title = "Error", description = "Not a valid command", color = discord.Color.green())
await ctx.send(embed = embed1)
#------------------------Keeps Bot Alive---------------------------------
bot.run(token)
您需要将
await bot.process_commands(message)
添加到on_消息事件中正如Docs告诉我们的:
相关问题 更多 >
编程相关推荐