好的,所以我有这段代码,但是当我尝试使用$ announce时,它不会写回Hello。实际上,它不响应我在异步定义下所做的任何事情。怎么会来?
我觉得我已经正确地完成了所有操作,这些教程是为了重写和使用我正在使用的教程。
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)
答案 0 :(得分:0)
我如下更改了您的代码,但请确保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)