我目前正在(缓慢地)学习python,并且已经开始编写一个不和谐的bot。但是,当我调用@ client.command函数时,在不协调中什么也不会发生。例如,.ping应回复“ pong!”。但没有任何反应,我也没有收到错误消息。
我的代码在
下方import discord
from discord.ext import commands
import asyncio
import time
import discord.client
client = commands.Bot(command_prefix=".")
messages = joined = 0
bad_words = ["example"]
channel = ["general"]
@client.command()
async def kick(ctx, userName: discord.Member):
await client.kick(userName)
@client.event(message)
async def on_ready():
id = client.get_guild(705455096749752323)
print("hello")
async def update_stats():
await client.wait_until_ready()
global messages, joined
while not client.is_closed():
try:
with open("stats.txt", "a") as f:
f.write(f"""Messages: {messages}, Members Joined {joined}, time: {time.time()}\n""")
messages = 0
joined = 0
await asyncio.sleep(5)
except Exception as e:
print(e)
@client.event
async def on_member_update(before, after):
n = after.nick
if n:
if n.lower().count("Crysis Wolfie") > 0:
last = before.nick
if last:
await after.edit(nick=last)
else:
await after.edit(nick="NO STOP THAT!")
@client.event
async def on_member_update(before, after):
n = after.game
if n:
if n.lower.count(f"""{before.n}""") > 0:
discord.message.channel.send()
@client.event
async def on_member_join(member):
global joined
joined += 1
for channel in member.server.channels:
if str(channel) == "general":
await discord.message.channel_send(f"""Welcome to the server {member.mention}""")
@client.event
async def on_message(message, yes=None):
# chat commands
id = client.get_guild(705455096749752323)
channels = ["general", "apply"]
global messages
messages = + 1
if str(message.channel) in channels:
if message.content.find("!hello") != -1:
await message.channel.send(f"""What's cooking {message.author.mention} looking good today :wink:""")
elif message.content == "!users":
await message.channel.send(f"""Number of members {id.member_count}""")
if message.content.find("NHS") != -1:
await message.channel.send("https://tenor.com/view/goodjob-clap-nicework-great-gif-7248435")
if message.content.find("wolfie") != -1:
await message.channel.purge(limit=1)
await message.channel.send("https://tenor.com/view/facepalm-really-stressed-mad-angry-gif-16109475")
if message.content.find("crysis") != -1:
await message.channel.purge(limit=1)
await message.channel.send("https://tenor.com/view/facepalm-really-stressed-mad-angry-gif-16109475")
if message.content.find("!apply") != -1:
await message.channel.send(f"""TESTING""")
for word in bad_words:
if message.content.count(word) > 0:
await message.channel.purge(limit=1)
await message.channel.send(f"""User {message.author.mention} watch your language!""")
try:
with open("badwordlog.txt", "a") as n:
n.write(f"""member: {message.author}, said {message.content}, at {time.time()}\n""")
print(f"""member: {message.author}, said {message.content}""");
except Exception as e:
print(e)
await client.process_commands(message)
@client.event
async def on_member_update(before, after): # needs fixing
n = before.status
if n != before:
await discord.message.channel.send(f"""have fun on {after} """)
@client.command()
async def create_invite(self, ctx): # needs fixing
self = bot
"""Create invite"""
link = await ctx.channel.create_invite(max_age=300)
await ctx.send("Here is an instant invite to your server: " + link)
@client.command()
async def clear(ctx, amount=5):
await ctx.channel.purge(limit=amount)
@client.command()
async def ping(ctx):
await ctx.send('pong!')
clint.run('my token is here but I have removed')
@ client.event函数运行良好且运行良好!但是client.command不执行任何操作:(。
谢谢