GVKun编程网logo

python中的Discord bot,检查命令是否为空(python 检查key 在不在 dict里)

26

本文将为您提供关于python中的Discordbot,检查命令是否为空的详细介绍,我们还将为您解释python检查key在不在dict里的相关知识,同时,我们还将为您提供关于BotDiscordPy

本文将为您提供关于python中的Discord bot,检查命令是否为空的详细介绍,我们还将为您解释python 检查key 在不在 dict里的相关知识,同时,我们还将为您提供关于Bot Discord Python:自动发送消息的问题、Discord Bot Image Loop (Python)、Discord Bot Python 提及、Discord Bot Python 语音聊天命令的实用信息。

本文目录一览:

python中的Discord bot,检查命令是否为空(python 检查key 在不在 dict里)

python中的Discord bot,检查命令是否为空(python 检查key 在不在 dict里)

你的问题有点不清楚。但我会在阅读时尝试回答。

我认为该模块不能很好地适应您定义参数的方式。它应该是 commandme(ctx,member=None,*message)。因为您希望将 message 收集在一个元组中。

commandme 的调用者必须像这样传递参数 ctx,Member,message=Message。那就是“message”参数作为关键字传递并且只有 1 个对象,而 member 参数将收集所有内容到一个元组中。

Bot Discord Python:自动发送消息的问题

Bot Discord Python:自动发送消息的问题

您可以使用 client.send 方法直接使用频道,而不是 channel.send

async def job():
    channel = client.get_channel(ID)
    message = "Hello !"
    await channel.send(message)

    # rest of your code here.

参考:

TextChannel#send

Discord Bot Image Loop (Python)

Discord Bot Image Loop (Python)

如何解决Discord Bot Image Loop (Python)?

所以这个 discord Bot 是由三个 Python 脚本组成的。

main.py

GoodAnimeMemes.py

webserver.py

脚本说明:

webserver.py 脚本用于让我的 discord 机器人保持活动状态(24/7 运行)。

GoodAnimeMemes.py 脚本应该从网站上查找图像;在这种情况下,Reddit 并下载它们。

并且 main.py 脚本应该运行 GoodAnimeMemes.py 脚本以循环重新创建新图像,并通过我的 discord 服务器发送它们。

然而,这是我遇到的问题,不知道如何解决。

如何在每次循环结束时重新加载网页,而不使用 webdriver?

我使用的网站(Replit.com)不支持 webdrive 库。

我的代码有效。但分开。如果我运行 GoodAnimeMemes.py,它将根据网站最新的 5 张图片下载新图片。 如果我运行 main.py 它将发送我之前运行的图像。 但是,如果网站发布了新图片,它不会自动下载新图片,而是不断发送相同的图片... 为了这篇文章比较小,我把 main.py 做成只发一张图片。

有什么建议吗?

ma​​in.py

import os
import time
import discord
from discord.ext import commands
import GoodAnimeMemes
from webserver import keep_alive

bot = commands.Bot(command_prefix=''$'')

# Server info display in Console when bot runs
@bot.event
async def on_ready():
    guild_count = 0
    for guild in bot.guilds:
        print(f"- {guild.id} (name: {guild.name})")
        guild_count = guild_count + 1
    print("Bot is in " + str(guild_count) + " guilds.")

# Bot; when command is used,then bot starts
@bot.event
async def on_message(message):
    while message.content == "/start":
        # Obtain data
        exec(open("GoodAnimeMemes.py").read())

        # Send data 1
        print("! Downloading image...")
        await message.channel.send("hey dirtbag",file=discord.File("anime1.jpg"))
        print("Sent!")
        time.sleep(60)
        os.remove("anime1.jpg")
        # Pause bot for 4hrs (14400sec)
    else:
      pass


keep_alive()
TOKEN = os.environ[''disCORD_TOKEN'']
bot.run(TOKEN)

GoodAnimeMemes.py

import requests
from bs4 import BeautifulSoup
import time


headers = {''User-Agent'': xxxxxxxxxxxxxxxxxxxxxxxxxx}

url = "https://www.reddit.com/r/Animemes/"


r = requests.get(url,headers=headers)
# Check connection to website
if r.status_code == 200:
  print("Connected to website!")
  time.sleep(0.5)
elif r.status_code == 400:
  print("Page does not exist...")
  time.sleep(0.5)
elif r.status_code == 500:
  print("Unauthorized access!")
  time.sleep(0.5)
else:
  pass


soup = BeautifulSoup(r.text,''html.parser'')
# Print Title of Website
print(soup.title.text)
time.sleep(0.5)


links = soup.find_all("img",{"alt": "Post image"})
# Print How Many Links There Are
print("There are",len(links),"links to work with.")
time.sleep(0.8)


images = []
for link in links:
  if link.has_attr(''src''):
    # append individual URL to "images" list
    images.append(link[''src''])

# Set initial n value
n = 0

# Loop through list of URLs and download each with name "anime" + n
for image in images:
  n = n + 1
  with open ("anime" + str(n) + ''.jpg'',''wb'') as f:
    im = requests.get(image)
    f.write(im.content)

版权 (c) 2021,zumbynsr 保留所有权利。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Discord Bot Python 提及

Discord Bot Python 提及

如何解决Discord Bot Python 提及?

我需要一个循环,在单独的消息中提及用户 x 次(x 是 0 到 1000 之间的随机选择) 已经试过了:

if message.content.startswith(''$ZSEN''):
    await message.channel.send(''MASZYNA LOSUJĄCA JEST PUSTA,I POSZŁO KURWA: '')
    for i in range(100):
        await message.channel.send(message.author.mention)  

解决方法

如果你想得到一个随机数,你必须使用随机库

使用

random.randint(0,1000)

用于导入库 from random import randint

Discord Bot Python 语音聊天命令

Discord Bot Python 语音聊天命令

如何解决Discord Bot Python 语音聊天命令?

我一直在制作一个 discord 机器人,当我在不同的屏幕上做其他事情时,它会播放音乐。我希望能够说“(机器人名称),暂停”或(机器人名称)恢复“这样我就不必在窗口之间来回跳跃。机器人正在提供音乐,并且我希望它只听来自角色“DJ”的用户的命令。这可能吗?我知道它雄心勃勃,但我无法停止思考哈哈!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

今天关于python中的Discord bot,检查命令是否为空python 检查key 在不在 dict里的分享就到这里,希望大家有所收获,若想了解更多关于Bot Discord Python:自动发送消息的问题、Discord Bot Image Loop (Python)、Discord Bot Python 提及、Discord Bot Python 语音聊天命令等相关知识,可以在本站进行查询。

本文标签: