Python 如何在discord.py中使用参数?

Python 如何在discord.py中使用参数?,python,discord.py,discord.py-rewrite,Python,Discord.py,Discord.py Rewrite,好的,我有这段代码,但当我尝试使用$announce时,它不会回写Hello。事实上,它对我放在async def下的任何内容都没有响应。为什么 我觉得我做的每件事都是正确的,我正在使用的教程都是用于重写和升级的 import discord from discord.ext import commands import os import time import random import weather from weather import Weather, Unit prefix =

好的,我有这段代码,但当我尝试使用$announce时,它不会回写Hello。事实上,它对我放在async def下的任何内容都没有响应。为什么

我觉得我做的每件事都是正确的,我正在使用的教程都是用于重写和升级的

import discord
from discord.ext import commands
import os
import time
import random
import weather
from weather import Weather, Unit

prefix = '$'
client = commands.Bot(command_prefix = prefix)
clattr = discord.Client()


@client.event
async def on_ready():
        await client.change_presence(status = discord.Status.online, activity = discord.Game('have a nice day!'))
        print("Bot is now online!")


@client.event
async def on_message(message):
  if message.content.startswith("$hello"):
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(time())
  if message.content.startswith("$dm"): 
    user = client.get_user(393921960817721355)
    dm_channel = user.dm_channel
    if (dm_channel==None):
      dm_channel = await user.create_dm()
    await dm_channel.send(f"""Hello!""")
  if message.content.startswith("$servers"):
    await message.channel.send(clattr.guilds)
  if message.content.startswith("$help"):
    await message.channel.send(f"""This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
  if message.content.startswith("$pinghelp"):
    await message.channel.send(f"""||@everyone|| This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")


@client.command()
async def announce(ctx, announcement):
  await ctx.send(f"""Hello""")




TOKEN = os.environ.get("DISCORD_BOT_SECRET")
client.run(TOKEN)

我如下所示更改了您的代码,但请确保discort.py与此代码位于同一文件夹中。如果您收到错误,请在您的条目中共享错误/警告,这将有所帮助

from discord import *
from discord.ext import commands
import os
import time
import random
import weather
from weather import Weather, Unit

prefix = '$'
client = commands.Bot(command_prefix = prefix)
clattr = Client()


@client.event
async def on_ready():
        await client.change_presence(status = Status.online, activity = Game('have a nice day!'))
        print("Bot is now online!")


@client.event
async def on_message(message):
  if message.content.startswith("$hello"):
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(time())
  if message.content.startswith("$dm"): 
    user = client.get_user(393921960817721355)
    dm_channel = user.dm_channel
    if (dm_channel==None):
      dm_channel = await user.create_dm()
    await dm_channel.send(f"""Hello!""")
  if message.content.startswith("$servers"):
    await message.channel.send(clattr.guilds)
  if message.content.startswith("$help"):
    await message.channel.send(f"""This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
  if message.content.startswith("$pinghelp"):
    await message.channel.send(f"""||@everyone|| This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")


@client.command()
async def announce(ctx, announcement):
  await ctx.send(f"""Hello""")




TOKEN = os.environ.get("DISCORD_BOT_SECRET")
client.run(TOKEN)

好的,我已经试过了,它给出了:回溯(最近一次调用最后一次):文件“main.py”,第4行,from discord import*ModuleNotFoundError:没有名为“discord”的模块是的,我已经安装了discord.py。你的Python版本是什么?是否可以打开Python IDE并运行import discord print discord。\u版本\u如果discord安装正确,它将显示版本。discord 1.0.1 discord.py 1.2.4 Python 3.7 64位