python - 为什么我不能在 python 的相同代码中使用命令和事件来制作 Discord bot
问题描述
import discord
from discord.ext import commands
import random
client=commands.Bot(command_prefix=".")
@client.event
async def on_ready(): #tells me if bot is ready
print("Bot je spreman")
@client.event
async def on_member_join(member): #Bot says hi to member in her dm
await member.create_dm()
await member.dm_channel.send(f"Bok{member.name}, dobrodošao")
@client.event
async def on_message(message): # Ignore messages made by the bot
if message.author == client.user:
return
odgovori = ["Dobro sam","Lose sam","OK sam"]
if message.content == "Kako si": #Bot responds to message(When i put this block in my code my commands wont work. How do i fix this?)
odg = random.choice(odgovori)
await message.channel.send(odg)
await client.process_commands(message)
@client.command(aliases=["kick"]) #Bot kick people from server
@commands.has_permissions(kick_members = True)
async def k(ctx,member : discord.Member,*,reason= "Bez razloga"):
await member.send("Izbacen si sa servera, zbog"+reason)
await member.kick(reason=reason)
@client.command(aliases=["clear"]) #Bot deletes messages
@commands.has_permissions(manage_messages = True)
async def c(ctx,kolicina=2):
await ctx.channel.purge(limit= kolicina)
@client.command()
async def ping(ctx): #Bot shows ping
await ctx.send(f"{round(client.latency * 1000)}ms")
client.run(TOKEN)
代码中的某些内容在克罗地亚语中,例如“odgovori”和一些字符串。我是编码新手,如果有什么东西让你感到抱歉,我很抱歉...................................... ..................................................... .....................................
解决方案
推荐阅读
- python - Cython,调用 shell 命令。性能提升
- vuejs2 - Axios 获取单一配置文件
- lit-element - 通过引用嵌套的 lit-element 传递对象
- string - Linux sed 命令:将 string1 替换为 string2 但仅当 string1 不在行尾时
- azure-devops - 不适用于测试计划测试套件和测试用例链接
- flutter - 颤动-使用文档中显示的bottomNavigationBar是非执行性的吗?
- javascript - HTML / CSS 全屏轮播图片
- javascript - 试图从我的搜索框中显示数据,但看起来它根本不起作用
- dialogflow-es - 在拒绝 Google 帐户链接后重新调用意图期间出现问题
- sorting - Elasticsearch 自定义排序