Python不和谐机器人

lvmkulzt  于 2023-01-04  发布在  Python
关注(0)|答案(1)|浏览(170)

我试图使一个机器人,可以创建角色,但机器人是不承认我的命令。
我试过使用OpenAI,但是它的知识有限。我只需要一个工作的方法来接收命令和创建角色。这是最大的
'

import sys

command_prefix = "!"

async def create_role(guild, role_name):
  # Create the role
  role = await guild.create_role(name=role_name)
  return role

@client.event
async def on_message(message):
  if message.content.startswith(f"{command_prefix}gr"):
    # Split the message into a list of arguments
    args = message.content.split(" ")
    # The name of the role is the second argument
    role_name = args[1]
    print(f"Creating role {role_name}")  # Debug statement
    # Create the role
    role = await create_role(message.guild, role_name)
    # Give the role to the user who sent the message
    await assign_role(message.author, role)
    await message.channel.send(
      f'Created role {role_name} and gave it to {message.author}')
client.run(
  'TOKEN')

'

gab6jxml

gab6jxml1#

您应该使用命令

from discord.ext import commands

bot = commands.Bot(command_prefix = '!') # prefix

@bot.command(name = "gr") # gr would be an example command, !gr <something>
async def do_on_command_function(ctx, msg):
    # msg will store the message after the command
    await ctx.send(arg)

相关问题