我如何让不和谐的机器人在命令后接收文本

How do i make a discord bot receive text after a command

我想成为一个假的 discord 机器人,所以我可以使用:!!send 或类似的东西。 我已准备好令牌并尝试了一些 repl.it 模板,但我不知道该怎么做。 这是我试过的代码:

import discord
import os
import time
import discord.ext
from discord.utils import get
from discord.ext import commands, tasks
from discord.ext.commands import has_permissions,  CheckFailure, check
os.environ["TOKEN"] = "no-token-for-you-to-see-here"
#^ basic imports for other features of discord.py and python ^

client = discord.Client()

client = commands.Bot(command_prefix = '!!') #put your own prefix here

@client.event
async def on_ready():
    print("bot online") #will print "bot online" in the console when the bot is online
    
    
@client.command(pass_context=True)
async def send(ctx,*,message):
    await client.say(message)

client.run(os.getenv("TOKEN")) #get your bot token and create a key named `TOKEN` to the secrets panel then paste your bot token as the value. 
#to keep your bot from shutting down use https://uptimerobot.com then create a https:// monitor and put the link to the website that appewars when you run this repl in the monitor and it will keep your bot alive by pinging the flask server
#enjoy!

已在线,但命令无效。

命令send应该是

@client.command()
async def send(ctx, *, message: str):
    await ctx.send(message)

此外,您定义了两个 client(s)。你只需要一个。

client = commands.Bot(command_prefix = '!!')

您还导入了一些您现在不需要的无用模块。

您的最终代码应如下所示:

import discord
from discord.ext import commands

client = commands.Bot(command_prefix="!!")

@client.event
async def on_ready():
    print("The bot is online")

@client.command()
async def send(ctx, *, message: str):
    await ctx.send(message)

client.run("token-of-the-bot")

请告诉我它是否有效。祝你有美好的一天:)