请帮助我使用我为我的 Discord 服务器制作的代码。 我不知道我在做什么,我需要弄清楚为什么当我使用 !aczping 时机器人没有响应(或者当我将它更改为 ! 前缀时)它什么都不做! 感谢您的帮助
import discord
import random
import os
from itertools import cycle
from discord.ext import commands, tasks
from discord.ext.commands import Bot
client = commands.Bot(command_prefix = "!acz")
status = cycle(['!acz // Senkuu by Rubix', 'acz!help - Made by AntsCzech', '!acz // Alpha v0.11.2, Made in Python (discord.py/repl.it)'])
bot = Bot("!acz")
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@tasks.loop(seconds=20)
async def change_status ():
await client.change_presence(activity=discord.Game(next(status)))
@client.command()
async def test(ctx):
await ctx.channel.send("Command executed")
@client.command()
async def ping(ctx):
await ctx.send(f'Pong! {round(client.latency * 1000)} ms')
@client.event
async def on_command_error(ctx, error):
if isinstance(error,commands.MissingRequiredArgument):
await ctx.send('Chybí část příkazu, zkus to znovu.')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!acz ahoj'):
await message.channel.send('Hoj hoj!')
if message.content.startswith('!acz help'):
await message.channel.send ('**Voláš o pomoc?** \nzatím ti nabídnu jen tyto příkazy: \n\n`!acz ahoj` Pozdravím tě! \n`!acz help` Pošlu ti tento seznam')
elif message.content.startswith("!users"):
await message.channel.send(f"""# počet Uživatelů na serveru: {id.member_count}""")
client.run(os.getenv('TOKEN'))
答案 0 :(得分:0)
命令至少需要消息意图
只需将您的客户端实例定义行更改为此
intents = discord.Intents.default()
client = commands.Bot(command_prefix = "!acz", intents=intents)
还有你的 bot = Bot(...) 没有意义,因为你将你的机器人实例定义为 client
。不过,我建议您将实例重命名为 bot。