【问题标题】:How do i make a discord bot receive text after a command如何让不和谐的机器人在命令后接收文本
【发布时间】:2021-12-07 06:00:00
【问题描述】:

我想成为一个假的不和谐机器人,所以我可以使用:!!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!

在线,但命令不起作用。

【问题讨论】:

  • 你好!你有任何minimum, reproducible examples 可以给我们看吗?如果没有看到您首先尝试过的东西,我们无法给您答案。请访问how-to-ask 以获得进一步的帮助。祝你好运!
  • @Bagle 好的,我把我用的代码放上去。

标签: python-3.x discord discord.py bots


【解决方案1】:

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")

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

【讨论】:

  • 是的,它有效,谢谢,现在我可以欺骗我的朋友,让他们认为我制作了有史以来最好的机器人!
  • 很高兴它成功了。另请检查我的回答是否已接受,以便对其他用户有所帮助。
  • 哦,我忘了,现在已经检查过了。
猜你喜欢
  • 2021-11-15
  • 2021-08-13
  • 2017-12-25
  • 2018-07-21
  • 2018-11-10
  • 2017-05-31
  • 2021-10-21
  • 2022-01-15
  • 2021-06-17
相关资源
最近更新 更多