首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不和谐模块从未使用过?

不和谐模块从未使用过?
EN

Stack Overflow用户
提问于 2019-07-14 12:05:30
回答 1查看 108关注 0票数 0

我在这里比较困惑,在试图研究答案时,我似乎找不到任何对我有意义的东西。我已经创建了一个有5个齿轮的不和谐机器人,在每个机器人中我import discord, os, and from discord.ext import commands in各种其他齿轮,我import其他模块,如random,视情况而定,但这是三个常见的模块。

问题是,在每个模块中,import discord都是灰色的(PyCharm集成开发环境),这表明它从未被使用过。尽管如此,我的机器人运行得很好。我似乎不能使用像wait_for()命令这样的东西,我猜是因为它在discord模块中?我没有正确地设置来使用它吗?

我将发布初始启动模块和另一个模块的一小段代码,而不是list模块。如果您需要更多信息,请让我知道。

初始启动:

代码语言:javascript
复制
import discord
import os
from discord.ext import commands

token = open("token.txt", "r").read()

client = commands.Bot(command_prefix = '!')

@client.command()
async def load(ctx, extension):
    client.load_extension("cogs." + extension)

@client.command()
async def unload(ctx, extension):
    client.unload_extension("cogs." + extension)

for filename in os.listdir("./cogs"):
    if filename.endswith('.py'):
        client.load_extension("cogs." + filename[:-3])

client.run(token)

另一个模块:

代码语言:javascript
复制
import discord
from discord.ext import commands
import os
import json
from pathlib import Path

class Sheet(commands.Cog):

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


    @commands.command()
    @commands.dm_only()
    async def viewchar(self, ctx):

         #Snipped code here to make it shorter.
         pass

    @viewchar.error
    async def stats_error(self, ctx, error):
        if isinstance(error, commands.PrivateMessageOnly):
            await ctx.send("You're an idiot, now everyone knows. Why would you want to display your character sheet "
                           "in a public room? PM me with the command.")
        else:
            raise error

def setup(client):
    client.add_cog(Sheet(client))
EN

回答 1

Stack Overflow用户

发布于 2019-07-15 21:46:55

这只意味着您的代码不会在任何地方直接引用discord模块。您可以通过commands模块获取所有内容。

您可以在不破坏任何内容的情况下从代码中删除import discord,因为依赖它的代码仍然会在幕后导入和使用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57024502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档