简体   繁体   English

Python Discord 机器人创建频道

[英]Python Discord Bot Create Channel

I'm trying to make a discord bot using the discord.py module.我正在尝试使用discord.py模块制作一个 discord 机器人。 I have structured my code in so called Cogs and now want to make one for creating text channels.我在所谓的 Cogs 中构建了我的代码,现在想制作一个用于创建文本通道的代码。 The Bot has the permissions it requires but is not doing anything when I call the command. Bot 具有所需的权限,但在我调用命令时没有执行任何操作。 I also don't get any error message, it just does nothing.我也没有收到任何错误消息,它什么都不做。 Thanks for helping already!感谢您的帮助!


from discord.ext import commands
import discord


class createchannel(commands.Cog):

    def __init__(self, client):
        self.client = client


    @commands.command()
    async def create(self, ctx, channel_name):
        guild = ctx.message.guild
        await guild.create_text_channel(channel_name)

def setup(client):
    client.add_cog(createchannel(client))

I found what was causing it not to work.我找到了导致它不起作用的原因。 The bot actually didn't have the permissions to edit the channel (which is weird because I authorized it with Amdin Rights) and I didn't get an error in the console because my cog that handles erros blocked it.该机器人实际上没有编辑频道的权限(这很奇怪,因为我用 Amdin Rights 授权了它)并且我没有在控制台中收到错误,因为我处理错误的 cog 阻止了它。

Ran into the same problem with disnake, and it took me reading through the api and testing things to figure it out.遇到与 disnake 相同的问题,我花了 api 阅读并进行测试才能弄清楚。 Since disnake is supposed to be forked off of discord.py try this因为 disnake 应该从 discord.py 分叉出来,试试这个

@commands.command(name="obvious", description="given")
async def command(ctx: Context):
    await ctx.message.guild.create_text_channel("channel_name")

This solved my issue, and now I just need to add the parameters to properly sort channel creation.这解决了我的问题,现在我只需要添加参数即可正确排序频道创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM