我想成为一个假的不和谐机器人,所以我可以使用:!!send
或类似的东西。我已经准备好了代币,并尝试了一些回复。它模板,但我不知道该怎么做。下面是我试过的代码:
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")
请告诉我它是否有效。祝你今天愉快!