有没有办法使用 python 将"say"命令编码到我的不和谐机器人中?



我尝试过不同的选项,这是我最想要的一个,但我似乎无法让它发挥作用。我能得到一些帮助吗?(对不起,我对编码很陌生(

这是我的代码:

import discord
from discord.ext import commands
client = discord.Client()
bot = commands.Bot(command_prefix='-')
@bot.command()
async def speak(ctx, *, text):
if ctx.message.author.id == ID here:
message = ctx.message
await message.delete()

await ctx.send(f"{text}")
else:
await ctx.send('I need text!')

感谢

您的else语句在这里没有什么意义。最好以不同的方式设置条件,即您想要text一次,如果没有发生这种情况,则存在else参数。

我也不知道这是否相关,但显然你只希望一个人能够执行这个命令。对于所有者,将有:

@commands.is_owner()

但如果你想让它指代另一个人,请使用:

@bot.command()
@commands.is_owner() # If you want to set this condition
async def say(ctx, *, text: str = None):
if ctx.message.author is not ID_You_Want:
await ctx.send("You are not allowed to use the command.")
return # Do not proceed
if text is None: # If just say is passed with no text
await ctx.send("Please insert a text.")
else:
await ctx.send(text) # Send the text

可选:您还可以删除使用ctx.message.delete()发送的命令

您的命令没有执行,因为您定义了clientbot。只需移除client = discord.Client()即可。

最新更新