小编Dan*_*n A的帖子

Discord.py 使机器人不与 DM 频道交互

我正在编写一个小型消息记录程序,我希望机器人只记录来自特定公会的消息,为此,我检查message.guild.id. 但是,当在 DM 通道中发送消息时,这会引发问题。我希望机器人完全忽略 Dm 频道,但我没有太多运气

编码:

@commands.Cog.listener()
    async def on_message(self, message):
        if message.guild.id == Guild ID HERE:
            print(f"{message.author} said --- {message.clean_content} --- in #{message.channel.name}")
        elif message.channel.type is discord.ChannelType.private:
            pass
Run Code Online (Sandbox Code Playgroud)
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "d:\Documents\Bots\DS BOT\cog\Listener.py", line 13, in on_message
    if message.guild.id == Guild ID HERE:
AttributeError: 'NoneType' object has no attribute 'id'
Ignoring exception in on_message
Traceback (most recent call last):
  File …
Run Code Online (Sandbox Code Playgroud)

python nonetype discord discord.py discord.py-rewrite

5
推荐指数
1
解决办法
1172
查看次数

Discord.py SSLCertVerificationError

我一直在开发一个机器人,昨晚它根据需要运行得很好,但是今天早上当我在终端中打开机器人时,出现以下错误:

Traceback (most recent call last):
  File "d:/Documents/Bots/DS BOT/bot.py", line 58, in <module>
    bot.run(token, bot=False)
  File "C:\Python38\lib\site-packages\discord\client.py", line 640, in run
    return future.result()
  File "C:\Python38\lib\site-packages\discord\client.py", line 621, in runner
    await self.start(*args, **kwargs)
  File "C:\Python38\lib\site-packages\discord\client.py", line 584, in start
    await self.login(*args, bot=bot)
  File "C:\Python38\lib\site-packages\discord\client.py", line 442, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "C:\Python38\lib\site-packages\discord\http.py", line 261, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "C:\Python38\lib\site-packages\discord\http.py", line 165, in request
    async with self.__session.request(method, url, **kwargs) as r:
  File "C:\Python38\lib\site-packages\aiohttp\client.py", line 1012, in __aenter__ …
Run Code Online (Sandbox Code Playgroud)

python python-3.x discord discord.py

4
推荐指数
1
解决办法
1573
查看次数

Python字典检查key是否存在

@commands.command(aliases=['lookup'])
    async def define(self, message, *, arg):
        dictionary=PyDictionary()
        Define = dictionary.meaning(arg)
        length = len(arg.split())
        if length == 1:
            embed = discord.Embed(description="**Noun:** " + Define["Noun"][0] + "\n\n**Verb:** " + Define["Verb"][0], color=0x00ff00)
            embed.set_author(name = ('Defenition of the word: ' + arg),
            icon_url=message.author.avatar_url)
            await message.send(embed=embed)
        else:
            CommandError = discord.Embed(description= "A Term must be only a single word" , color=0xfc0328)
            await message.channel.send(embed=CommandError)
Run Code Online (Sandbox Code Playgroud)

我想检查 和 是否NounVerb字典中Define,因为当一个单词在其定义中只包含一个名词时,它会抛出一个错误,因为我试图通过机器人输出名词和动词,看看我得到了什么。我是字典新手,非常感谢任何帮助

python dictionary python-3.x discord.py

3
推荐指数
1
解决办法
3万
查看次数

Python 小写​​和大写字符串

有没有办法将字符串转换为一系列大写和小写字母?

例如,“公里”?“千米”。

python string lowercase uppercase

1
推荐指数
1
解决办法
205
查看次数