python - 我对使用 python 制作不和谐的机器人非常陌生,由于某种原因,机器人不响应命令
问题描述
如标题中所述,我是 Python 新手(一般编程),我尝试制作一个机器人,但是该机器人不响应命令。我关注/浏览了多个 youtube 教程和文章,但我找不到解决问题的方法。
import discord
from discord.ext.commands import Bot
bot = Bot(".")
@bot.event
async def on_ready():
print("kram is now online")
await bot.change_presence(activity=discord.Game(name="This bot is a WIP"))
@bot.event
async def on_message(message):
if message.author == bot.user:
@bot.command(aliases=["gp"])
async def ghostping(ctx, amount=2):
await ctx.send("@everyone")
await ctx.channel.purge(limit = amount)
@bot.command()
async def help(ctx):
await ctx.send("As of right now, .gp is the only working command.")
bot.run("I'm hiding my token")
解决方案
嘿,你为什么不试试这个,而不是同样的事情,但我删除了 on 消息
import discord
from discord.ext.commands import Bot
bot = Bot(".")
@bot.event
async def on_ready():
print("kram is now online")
await bot.change_presence(activity=discord.Game(name="This bot is a WIP"))
@bot.command(aliases=["gp"])
async def ghostping(ctx, amount=2):
await ctx.send("@everyone")
await ctx.channel.purge(limit = amount)
@bot.command()
async def help(ctx):
await ctx.send("As of right now, .gp is the only working command.")
bot.run("I'm hiding my token")
这应该在使用 cogs 时起作用,并且当您有命令时,无需将其放入 on_message 事件中。我建议你看这个系列(刚开始时真的很有帮助):
https://www.youtube.com/watch?v=yrHbGhem6I4&list=UUR-zOCvDCayyYy1flR5qaAg
推荐阅读
- database - MongoDB 社区版
- sequelize.js - sequelize-cli:运行单个种子文件很慢
- bash - 在没有root权限的Rhel6.5上安装meld
- python-3.x - 使用'for'循环迭代给定函数的列表
- python - 如何在 DataFrame 中正确设置列
- pine-script - 我怎样才能让每个入口点只有一个出口?
- flutter - Flutter:如何设置父小部件的状态
- c++ - C1189 #错误:
使用 /clr 或 /clr:pure 编译时不支持 - typescript - typescript:如何将类型的属性简化为特定类型的属性?
- c++ - 如何让 GetLocaleInfoEx 以特定语言返回其数据?