如何让bot.command()工作?(discord.py)



我尝试了我能找到的一切,但除了之外,似乎什么都不起作用

import discord
from discord.ext import commands
import os
import requests
import json
import random
import string

my_secret = os.environ['my_secret']
client = discord.Client()
@client.event
async def on_ready():
print("we're in boys ({0.user})".format(client))
prefix = "~"
bot = commands.Bot(command_prefix='~')

@client.event
async def on_message(message):
username = str(message.author) .split(' #')[0]
user_message = str(message.content)
channel = str(message.channel.name)
print(f'{username}: {user_message} ({channel})')

if message.author == client.user:
return
#a bunch of commands here
@bot.command()
async def test(ctx, arg1, arg2):
await ctx.send(f'You passed {arg1} and {arg2}')

try:
client.run(os.getenv('my_secret'))

如果它有任何不同,我会在replit 上运行这个

这是我得到的错误

File "main.py", line 107
@bot.command()
^
IndentationError: expected an indented block

这是我第一次尝试制作不和机器人,所以我错过可能是一个明显的错误

尝试将@bot.command()重命名为@client.command()如果你想让机器人长时间工作,如果我正确地理解你在replit.com中包含了机器人,如果是这样,创建一个名为webserver.py的文件,然后导入from webserver import keep_alive转到你创建的文件并在那里写

from flask import Flask
from threading import Thread
app = Flask('')
@app.route('/')
def home():
return "Wok"
def run():
app.run(host='0.0.0.0',port=8080)
def keep_alive():
t = Thread(target=run)
t.start()

返回到我的并写下`

keep_alive()
client.run(os.environ['TOKEN'])

最新更新